Replace fixed-size lookup_maps array with hb_array_t

This commit is contained in:
Behdad Esfahbod 2011-05-05 14:38:16 -04:00
parent 6843569d2c
commit 265ac614ea
3 changed files with 30 additions and 32 deletions

View File

@ -36,8 +36,6 @@
HB_BEGIN_DECLS
#define MAX_LOOKUPS 1000 /* FIXME */
static const hb_tag_t table_tags[2] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS};
struct hb_ot_map_t {
@ -113,12 +111,12 @@ struct hb_ot_map_t {
}
inline void substitute (hb_face_t *face, hb_buffer_t *buffer) const {
for (unsigned int i = 0; i < lookup_count[0]; i++)
for (unsigned int i = 0; i < lookup_maps[0].len; i++)
hb_ot_layout_substitute_lookup (face, buffer, lookup_maps[0][i].index, lookup_maps[0][i].mask);
}
inline void position (hb_font_t *font, hb_face_t *face, hb_buffer_t *buffer) const {
for (unsigned int i = 0; i < lookup_count[1]; i++)
for (unsigned int i = 0; i < lookup_maps[1].len; i++)
hb_ot_layout_position_lookup (font, buffer, lookup_maps[1][i].index, lookup_maps[1][i].mask);
}
@ -126,11 +124,10 @@ struct hb_ot_map_t {
hb_mask_t global_mask;
hb_prealloced_array_t<feature_info_t,16> feature_infos; /* used before compile() only */
hb_prealloced_array_t<feature_map_t, 16> feature_maps;
hb_prealloced_array_t<feature_info_t,8> feature_infos; /* used before compile() only */
hb_prealloced_array_t<feature_map_t, 8> feature_maps;
lookup_map_t lookup_maps[2][MAX_LOOKUPS]; /* GSUB/GPOS */
unsigned int lookup_count[2];
hb_prealloced_array_t<lookup_map_t, 32> lookup_maps[2]; /* GSUB/GPOS */
};

View File

@ -39,23 +39,28 @@ hb_ot_map_t::add_lookups (hb_face_t *face,
unsigned int feature_index,
hb_mask_t mask)
{
unsigned int i = MAX_LOOKUPS - lookup_count[table_index];
lookup_map_t *lookups = lookup_maps[table_index] + lookup_count[table_index];
unsigned int lookup_indices[32];
unsigned int offset, len;
unsigned int *lookup_indices = (unsigned int *) lookups;
offset = 0;
do {
len = ARRAY_LENGTH (lookup_indices);
hb_ot_layout_feature_get_lookup_indexes (face,
table_tags[table_index],
feature_index,
offset, &len,
lookup_indices);
hb_ot_layout_feature_get_lookup_indexes (face,
table_tags[table_index],
feature_index,
0, &i,
lookup_indices);
for (unsigned int i = 0; i < len; i++) {
lookup_map_t *lookup = lookup_maps[table_index].push ();
if (unlikely (!lookup))
return;
lookup->mask = mask;
lookup->index = lookup_indices[i];
}
lookup_count[table_index] += i;
while (i--) {
lookups[i].mask = mask;
lookups[i].index = lookup_indices[i];
}
offset += len;
} while (len == ARRAY_LENGTH (lookup_indices));
}
@ -64,7 +69,6 @@ hb_ot_map_t::compile (hb_face_t *face,
const hb_segment_properties_t *props)
{
global_mask = 1;
lookup_count[0] = lookup_count[1] = 0;
if (!feature_infos.len)
return;
@ -176,17 +180,16 @@ hb_ot_map_t::compile (hb_face_t *face,
add_lookups (face, table_index, feature_maps[i].index[table_index], feature_maps[i].mask);
/* Sort lookups and merge duplicates */
qsort (lookup_maps[table_index], lookup_count[table_index], sizeof (lookup_maps[table_index][0]), (hb_compare_func_t) lookup_map_t::cmp);
if (lookup_count[table_index])
lookup_maps[table_index].sort ();
if (lookup_maps[table_index].len)
{
unsigned int j = 0;
for (unsigned int i = 1; i < lookup_count[table_index]; i++)
for (unsigned int i = 1; i < lookup_maps[table_index].len; i++)
if (lookup_maps[table_index][i].index != lookup_maps[table_index][j].index)
lookup_maps[table_index][++j] = lookup_maps[table_index][i];
else
lookup_maps[table_index][j].mask |= lookup_maps[table_index][i].mask;
j++;
lookup_count[table_index] = j;
lookup_maps[table_index].shrink (j + 1);
}
}
}

View File

@ -235,10 +235,8 @@ struct hb_prealloced_array_t {
Type *array;
Type static_array[StaticSize];
inline Type& operator [] (unsigned int i)
{
return array[i];
}
inline Type& operator [] (unsigned int i) { return array[i]; }
inline const Type& operator [] (unsigned int i) const { return array[i]; }
inline Type *push (void)
{