Add UnsizedArrayOf::as_array() instead of hb_array() template

This commit is contained in:
Behdad Esfahbod 2018-11-02 11:46:24 -04:00
parent 1cf075ecb6
commit 72462eb765
5 changed files with 8 additions and 15 deletions

View File

@ -55,7 +55,7 @@ struct TrackTableEntry
unsigned int index, unsigned int index,
unsigned int nSizes) const unsigned int nSizes) const
{ {
return hb_array (base+valuesZ, nSizes)[index]; return (base+valuesZ).as_array (nSizes)[index];
} }
public: public:

View File

@ -572,8 +572,6 @@ struct hb_array_t
T *arrayZ; T *arrayZ;
unsigned int len; unsigned int len;
}; };
template <typename T> static inline
hb_array_t<T> hb_array (T *array, unsigned int len) { return hb_array_t<T> (array, len); }
struct HbOpOr struct HbOpOr

View File

@ -330,7 +330,7 @@ struct ResourceTypeRecord
inline const ResourceRecord& get_resource_record (unsigned int i, inline const ResourceRecord& get_resource_record (unsigned int i,
const void *type_base) const const void *type_base) const
{ {
return hb_array (type_base+resourcesZ, get_resource_count ())[i]; return (type_base+resourcesZ).as_array (get_resource_count ())[i];
} }
inline bool sanitize (hb_sanitize_context_t *c, inline bool sanitize (hb_sanitize_context_t *c,

View File

@ -346,6 +346,9 @@ struct UnsizedArrayOf
inline unsigned int get_size (unsigned int len) const inline unsigned int get_size (unsigned int len) const
{ return len * Type::static_size; } { return len * Type::static_size; }
inline hb_array_t<Type> as_array (unsigned int len) { return hb_array_t<Type> (arrayZ, len); }
inline hb_array_t<const Type> as_array (unsigned int len) const { return hb_array_t<const Type> (arrayZ, len); }
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
@ -393,14 +396,6 @@ struct UnsizedArrayOf
public: public:
DEFINE_SIZE_ARRAY (0, arrayZ); DEFINE_SIZE_ARRAY (0, arrayZ);
}; };
} /* namespace OT */
template <typename T> static inline
hb_array_t<T> hb_array (OT::UnsizedArrayOf<T> &array, unsigned int len)
{ return hb_array (array.arrayZ, len); }
template <typename T> static inline
hb_array_t<const T> hb_array (const OT::UnsizedArrayOf<T> &array, unsigned int len)
{ return hb_array (array.arrayZ, len); }
namespace OT {
/* Unsized array of offset's */ /* Unsized array of offset's */
template <typename Type, typename OffsetType, bool has_null=true> template <typename Type, typename OffsetType, bool has_null=true>

View File

@ -55,7 +55,7 @@ struct CPALV1Tail
{ {
if (!paletteFlagsZ) return HB_OT_COLOR_PALETTE_FLAG_DEFAULT; if (!paletteFlagsZ) return HB_OT_COLOR_PALETTE_FLAG_DEFAULT;
return (hb_ot_color_palette_flags_t) (uint32_t) return (hb_ot_color_palette_flags_t) (uint32_t)
hb_array (base+paletteFlagsZ, palette_count)[palette_index]; (base+paletteFlagsZ).as_array (palette_count)[palette_index];
} }
inline hb_ot_name_id_t inline hb_ot_name_id_t
@ -64,7 +64,7 @@ struct CPALV1Tail
unsigned int palette_count) const unsigned int palette_count) const
{ {
if (!paletteLabelsZ) return HB_OT_NAME_ID_INVALID; if (!paletteLabelsZ) return HB_OT_NAME_ID_INVALID;
return hb_array (base+paletteLabelsZ, palette_count)[palette_index]; return (base+paletteLabelsZ).as_array (palette_count)[palette_index];
} }
inline hb_ot_name_id_t inline hb_ot_name_id_t
@ -73,7 +73,7 @@ struct CPALV1Tail
unsigned int color_count) const unsigned int color_count) const
{ {
if (!colorLabelsZ) return HB_OT_NAME_ID_INVALID; if (!colorLabelsZ) return HB_OT_NAME_ID_INVALID;
return hb_array (base+colorLabelsZ, color_count)[color_index]; return (base+colorLabelsZ).as_array (color_count)[color_index];
} }
public: public: