Replace fixed-size feature_maps array with hb_array_t
This commit is contained in:
parent
44b0a4d2fc
commit
6843569d2c
|
@ -82,8 +82,6 @@ struct hb_ot_map_t {
|
|||
|
||||
public:
|
||||
|
||||
hb_ot_map_t (void) : feature_count (0) {}
|
||||
|
||||
void add_feature (hb_tag_t tag, unsigned int value, bool global)
|
||||
{
|
||||
feature_info_t *info = feature_infos.push();
|
||||
|
@ -104,13 +102,13 @@ struct hb_ot_map_t {
|
|||
inline hb_mask_t get_global_mask (void) const { return global_mask; }
|
||||
|
||||
inline hb_mask_t get_mask (hb_tag_t tag, unsigned int *shift = NULL) const {
|
||||
const feature_map_t *map = (const feature_map_t *) bsearch (&tag, feature_maps, feature_count, sizeof (feature_maps[0]), (hb_compare_func_t) feature_map_t::cmp);
|
||||
const feature_map_t *map = feature_maps.bsearch (&tag);
|
||||
if (shift) *shift = map ? map->shift : 0;
|
||||
return map ? map->mask : 0;
|
||||
}
|
||||
|
||||
inline hb_mask_t get_1_mask (hb_tag_t tag) const {
|
||||
const feature_map_t *map = (const feature_map_t *) bsearch (&tag, feature_maps, feature_count, sizeof (feature_maps[0]), (hb_compare_func_t) feature_map_t::cmp);
|
||||
const feature_map_t *map = feature_maps.bsearch (&tag);
|
||||
return map ? map->_1_mask : 0;
|
||||
}
|
||||
|
||||
|
@ -128,10 +126,8 @@ struct hb_ot_map_t {
|
|||
|
||||
hb_mask_t global_mask;
|
||||
|
||||
unsigned int feature_count;
|
||||
hb_prealloced_array_t<feature_info_t,16> feature_infos; /* used before compile() only */
|
||||
#define MAX_FEATURES 100
|
||||
feature_map_t feature_maps[MAX_FEATURES];
|
||||
hb_prealloced_array_t<feature_map_t, 16> feature_maps;
|
||||
|
||||
lookup_map_t lookup_maps[2][MAX_LOOKUPS]; /* GSUB/GPOS */
|
||||
unsigned int lookup_count[2];
|
||||
|
|
|
@ -106,10 +106,8 @@ hb_ot_map_t::compile (hb_face_t *face,
|
|||
|
||||
|
||||
/* Allocate bits now */
|
||||
feature_count = feature_infos.len;
|
||||
unsigned int next_bit = 1;
|
||||
j = 0;
|
||||
for (unsigned int i = 0; i < feature_count; i++) {
|
||||
for (unsigned int i = 0; i < feature_infos.len; i++) {
|
||||
const feature_info_t *info = &feature_infos[i];
|
||||
|
||||
unsigned int bits_needed;
|
||||
|
@ -137,7 +135,9 @@ hb_ot_map_t::compile (hb_face_t *face,
|
|||
continue;
|
||||
|
||||
|
||||
feature_map_t *map = &feature_maps[j++];
|
||||
feature_map_t *map = feature_maps.push ();
|
||||
if (unlikely (!map))
|
||||
break;
|
||||
|
||||
map->tag = info->tag;
|
||||
map->index[0] = feature_index[0];
|
||||
|
@ -156,7 +156,7 @@ hb_ot_map_t::compile (hb_face_t *face,
|
|||
map->_1_mask = (1 << map->shift) & map->mask;
|
||||
|
||||
}
|
||||
feature_count = j;
|
||||
feature_infos.shrink (0); /* Done with these */
|
||||
|
||||
|
||||
for (unsigned int table_index = 0; table_index < 2; table_index++) {
|
||||
|
@ -172,7 +172,7 @@ hb_ot_map_t::compile (hb_face_t *face,
|
|||
&required_feature_index))
|
||||
add_lookups (face, table_index, required_feature_index, 1);
|
||||
|
||||
for (unsigned i = 0; i < feature_count; i++)
|
||||
for (unsigned i = 0; i < feature_maps.len; i++)
|
||||
add_lookups (face, table_index, feature_maps[i].index[table_index], feature_maps[i].mask);
|
||||
|
||||
/* Sort lookups and merge duplicates */
|
||||
|
|
|
@ -370,7 +370,7 @@ hb_ot_shape (hb_font_t *font,
|
|||
const hb_feature_t *features,
|
||||
unsigned int num_features)
|
||||
{
|
||||
hb_ot_shape_plan_t plan;
|
||||
hb_ot_shape_plan_t plan = hb_ot_shape_plan_t ();
|
||||
|
||||
hb_ot_shape_plan_internal (&plan, font->face, &buffer->props, features, num_features);
|
||||
hb_ot_shape_execute (&plan, font, buffer, features, num_features);
|
||||
|
|
|
@ -285,10 +285,36 @@ struct hb_prealloced_array_t {
|
|||
/* TODO: shrink array if needed */
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Type *find (T v) {
|
||||
for (unsigned int i = 0; i < len; i++)
|
||||
if (array[i] == v)
|
||||
return &array[i];
|
||||
return NULL;
|
||||
}
|
||||
template <typename T>
|
||||
inline const Type *find (T v) const {
|
||||
for (unsigned int i = 0; i < len; i++)
|
||||
if (array[i] == v)
|
||||
return &array[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline void sort (void)
|
||||
{
|
||||
qsort (array, len, sizeof (Type), (hb_compare_func_t) Type::cmp);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Type *bsearch (T *key)
|
||||
{
|
||||
return (Type *) ::bsearch (key, array, len, sizeof (Type), (hb_compare_func_t) Type::cmp);
|
||||
}
|
||||
template <typename T>
|
||||
inline const Type *bsearch (T *key) const
|
||||
{
|
||||
return (const Type *) ::bsearch (key, array, len, sizeof (Type), (hb_compare_func_t) Type::cmp);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
|
@ -300,22 +326,12 @@ struct hb_set_t
|
|||
{
|
||||
hb_array_t <item_t> items;
|
||||
|
||||
private:
|
||||
|
||||
template <typename T>
|
||||
inline item_t *find (T v) {
|
||||
for (unsigned int i = 0; i < items.len; i++)
|
||||
if (items[i] == v)
|
||||
return &items[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
template <typename T>
|
||||
inline bool insert (T v)
|
||||
{
|
||||
item_t *item = find (v);
|
||||
item_t *item = items.find (v);
|
||||
if (item)
|
||||
item->finish ();
|
||||
else
|
||||
|
@ -328,7 +344,7 @@ struct hb_set_t
|
|||
template <typename T>
|
||||
inline void remove (T v)
|
||||
{
|
||||
item_t *item = find (v);
|
||||
item_t *item = items.find (v);
|
||||
if (!item) return;
|
||||
|
||||
item->finish ();
|
||||
|
@ -339,7 +355,7 @@ struct hb_set_t
|
|||
template <typename T>
|
||||
inline item_t *get (T v)
|
||||
{
|
||||
return find (v);
|
||||
return items.find (v);
|
||||
}
|
||||
|
||||
void finish (void) {
|
||||
|
|
Loading…
Reference in New Issue