Replace fixed-size feature_infos array with hb_array_t

This commit is contained in:
Behdad Esfahbod 2011-05-05 13:42:19 -04:00
parent b214ec3ac0
commit 44b0a4d2fc
3 changed files with 22 additions and 8 deletions

View File

@ -36,7 +36,6 @@
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};
@ -87,9 +86,10 @@ struct hb_ot_map_t {
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;
@ -129,7 +129,8 @@ struct hb_ot_map_t {
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 */

View File

@ -66,7 +66,7 @@ hb_ot_map_t::compile (hb_face_t *face,
global_mask = 1;
lookup_count[0] = lookup_count[1] = 0;
if (!feature_count)
if (!feature_infos.len)
return;
@ -88,9 +88,9 @@ hb_ot_map_t::compile (hb_face_t *face,
/* 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 {
@ -102,10 +102,11 @@ hb_ot_map_t::compile (hb_face_t *face,
/* 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++) {

View File

@ -277,6 +277,18 @@ struct hb_prealloced_array_t {
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>