HB_BEGIN_DECLS
-#define MAX_FEATURES 100 /* FIXME */
#define MAX_LOOKUPS 1000 /* FIXME */
static const hb_tag_t table_tags[2] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS};
void add_feature (hb_tag_t tag, unsigned int value, bool global)
{
- feature_info_t *info = &feature_infos[feature_count++];
+ feature_info_t *info = feature_infos.push();
+ if (unlikely (!info)) return;
info->tag = tag;
- info->seq = feature_count;
+ info->seq = feature_infos.len;
info->max_value = value;
info->global = global;
info->default_value = global ? value : 0;
hb_mask_t global_mask;
unsigned int feature_count;
- feature_info_t feature_infos[MAX_FEATURES]; /* used before compile() only */
+ 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];
lookup_map_t lookup_maps[2][MAX_LOOKUPS]; /* GSUB/GPOS */
global_mask = 1;
lookup_count[0] = lookup_count[1] = 0;
- if (!feature_count)
+ if (!feature_infos.len)
return;
/* Sort features and merge duplicates */
- qsort (feature_infos, feature_count, sizeof (feature_infos[0]), (hb_compare_func_t) feature_info_t::cmp);
+ feature_infos.sort ();
unsigned int j = 0;
- for (unsigned int i = 1; i < feature_count; i++)
+ for (unsigned int i = 1; i < feature_infos.len; i++)
if (feature_infos[i].tag != feature_infos[j].tag)
feature_infos[++j] = feature_infos[i];
else {
/* Inherit default_value from j */
}
}
- feature_count = j + 1;
+ feature_infos.shrink (j + 1);
/* Allocate bits now */
+ feature_count = feature_infos.len;
unsigned int next_bit = 1;
j = 0;
for (unsigned int i = 0; i < feature_count; i++) {
len--;
/* TODO: shrink array if needed */
}
+
+ inline void shrink (unsigned int l)
+ {
+ if (l < len)
+ len = l;
+ /* TODO: shrink array if needed */
+ }
+
+ inline void sort (void)
+ {
+ qsort (array, len, sizeof (Type), (hb_compare_func_t) Type::cmp);
+ }
};
template <typename Type>