From 44b0a4d2fc62689fc56ef57f412b4bb1e439a614 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 5 May 2011 13:42:19 -0400 Subject: [PATCH] Replace fixed-size feature_infos array with hb_array_t --- src/hb-ot-map-private.hh | 9 +++++---- src/hb-ot-map.cc | 9 +++++---- src/hb-private.hh | 12 ++++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/hb-ot-map-private.hh b/src/hb-ot-map-private.hh index e0fe51b..3b0cc19 100644 --- a/src/hb-ot-map-private.hh +++ b/src/hb-ot-map-private.hh @@ -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_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 */ diff --git a/src/hb-ot-map.cc b/src/hb-ot-map.cc index 9b15305..d313da7 100644 --- a/src/hb-ot-map.cc +++ b/src/hb-ot-map.cc @@ -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++) { diff --git a/src/hb-private.hh b/src/hb-private.hh index 26e0a69..d3edad3 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -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 -- 2.7.4