提交 8f08c327 编写于 作者: B Behdad Esfahbod

Minor cleanup

上级 a806762a
...@@ -718,13 +718,9 @@ struct SortedArrayOf : ArrayOf<Type> { ...@@ -718,13 +718,9 @@ struct SortedArrayOf : ArrayOf<Type> {
template <typename SearchType> template <typename SearchType>
inline int search (const SearchType &x) const { inline int search (const SearchType &x) const {
class Cmp { class Cmp {
public: static int cmp (const void *p1, const void *p2) { public: static int cmp (const SearchType *a, const Type *b) { return b->cmp (*a); }
const SearchType *a = reinterpret_cast<const SearchType *>(p1);
const Type *b = reinterpret_cast<const Type *>(p2);
return b->cmp (*a);
}
}; };
const Type *p = (const Type *) bsearch (&x, this->array, this->len, sizeof (this->array[0]), Cmp::cmp); const Type *p = (const Type *) bsearch (&x, this->array, this->len, sizeof (this->array[0]), (hb_compare_func_t) Cmp::cmp);
return p ? p - this->array : -1; return p ? p - this->array : -1;
} }
}; };
......
...@@ -43,23 +43,16 @@ static const hb_tag_t table_tags[2] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS}; ...@@ -43,23 +43,16 @@ static const hb_tag_t table_tags[2] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS};
struct hb_mask_allocator_t { struct hb_mask_allocator_t {
private:
struct feature_info_t { struct feature_info_t {
hb_tag_t tag; hb_tag_t tag;
unsigned int value; unsigned int value;
unsigned int seq; unsigned int seq;
bool global; bool global;
static int static int cmp (const feature_info_t *a, const feature_info_t *b)
cmp (const void *p1, const void *p2) { return (a->tag != b->tag) ? (a->tag < b->tag ? -1 : 1) : (a->seq < b->seq ? -1 : 1); }
{
const feature_info_t *a = reinterpret_cast<const feature_info_t *>(p1);
const feature_info_t *b = reinterpret_cast<const feature_info_t *>(p2);
if (a->tag != b->tag)
return a->tag < b->tag ? -1 : 1;
return a->seq < b->seq ? -1 : 1;
}
}; };
struct feature_map_t { struct feature_map_t {
...@@ -68,28 +61,16 @@ struct hb_mask_allocator_t { ...@@ -68,28 +61,16 @@ struct hb_mask_allocator_t {
unsigned int shift; unsigned int shift;
hb_mask_t mask; hb_mask_t mask;
static int static int cmp (const feature_map_t *a, const feature_map_t *b)
cmp (const void *p1, const void *p2) { return a->tag < b->tag ? -1 : a->tag > b->tag ? 1 : 0; }
{
const feature_map_t *a = reinterpret_cast<const feature_map_t *>(p1);
const feature_map_t *b = reinterpret_cast<const feature_map_t *>(p2);
return a->tag < b->tag ? -1 : a->tag > b->tag ? 1 : 0;
}
}; };
struct lookup_map_t { struct lookup_map_t {
unsigned int index; unsigned int index;
hb_mask_t mask; hb_mask_t mask;
static int static int cmp (const lookup_map_t *a, const lookup_map_t *b)
cmp (const void *p1, const void *p2) { return a->index < b->index ? -1 : a->index > b->index ? 1 : 0; }
{
const lookup_map_t *a = reinterpret_cast<const lookup_map_t *>(p1);
const lookup_map_t *b = reinterpret_cast<const lookup_map_t *>(p2);
return a->index < b->index ? -1 : a->index > b->index ? 1 : 0;
}
}; };
...@@ -120,6 +101,7 @@ struct hb_mask_allocator_t { ...@@ -120,6 +101,7 @@ struct hb_mask_allocator_t {
public:
hb_mask_allocator_t (void) : feature_count (0) {} hb_mask_allocator_t (void) : feature_count (0) {}
...@@ -160,10 +142,8 @@ struct hb_mask_allocator_t { ...@@ -160,10 +142,8 @@ struct hb_mask_allocator_t {
} }
/* Sort the features so we can bsearch later */ /* Sort features and merge duplicates */
qsort (feature_infos, feature_count, sizeof (feature_infos[0]), feature_info_t::cmp); qsort (feature_infos, feature_count, sizeof (feature_infos[0]), (hb_compare_func_t) feature_info_t::cmp);
/* Remove dups, let later-occurring features override earlier ones. */
unsigned int j = 0; unsigned int j = 0;
for (unsigned int i = 1; i < feature_count; i++) for (unsigned int i = 1; i < feature_count; i++)
if (feature_infos[i].tag != feature_infos[j].tag) if (feature_infos[i].tag != feature_infos[j].tag)
...@@ -248,9 +228,7 @@ struct hb_mask_allocator_t { ...@@ -248,9 +228,7 @@ struct hb_mask_allocator_t {
add_lookups (c, table_index, feature_maps[i].index[table_index], feature_maps[i].mask); add_lookups (c, table_index, feature_maps[i].index[table_index], feature_maps[i].mask);
/* Sort lookups and merge duplicates */ /* 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);
qsort (lookup_maps[table_index], lookup_count[table_index], sizeof (lookup_maps[table_index][0]), lookup_map_t::cmp);
if (lookup_count[table_index]) if (lookup_count[table_index])
{ {
unsigned int j = 0; unsigned int j = 0;
...@@ -268,22 +246,17 @@ struct hb_mask_allocator_t { ...@@ -268,22 +246,17 @@ struct hb_mask_allocator_t {
hb_mask_t get_global_mask (void) { return global_mask; } hb_mask_t get_global_mask (void) { return global_mask; }
hb_mask_t get_mask (hb_tag_t tag, unsigned int *shift) const { hb_mask_t get_mask (hb_tag_t tag, unsigned int *shift) const {
const feature_map_t *map = (const feature_map_t *) bsearch (&tag, feature_maps, feature_count, sizeof (feature_maps[0]), feature_map_t::cmp); 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);
if (likely (map)) { if (shift) *shift = map ? map->shift : 0;
if (shift) *shift = map->shift; return map ? map->mask : 0;
return map->mask;
} else {
if (shift) *shift = 0;
return 0;
}
} }
void substitute (hb_ot_shape_context_t *c) const { inline void substitute (hb_ot_shape_context_t *c) const {
for (unsigned int i = 0; i < lookup_count[0]; i++) for (unsigned int i = 0; i < lookup_count[0]; i++)
hb_ot_layout_substitute_lookup (c->face, c->buffer, lookup_maps[0][i].index, lookup_maps[0][i].mask); hb_ot_layout_substitute_lookup (c->face, c->buffer, lookup_maps[0][i].index, lookup_maps[0][i].mask);
} }
void position (hb_ot_shape_context_t *c) const { inline void position (hb_ot_shape_context_t *c) const {
for (unsigned int i = 0; i < lookup_count[1]; i++) for (unsigned int i = 0; i < lookup_count[1]; i++)
hb_ot_layout_position_lookup (c->font, c->face, c->buffer, lookup_maps[1][i].index, lookup_maps[1][i].mask); hb_ot_layout_position_lookup (c->font, c->face, c->buffer, lookup_maps[1][i].index, lookup_maps[1][i].mask);
} }
......
...@@ -591,10 +591,9 @@ static const LangTag ot_languages[] = { ...@@ -591,10 +591,9 @@ static const LangTag ot_languages[] = {
}; };
static int static int
lang_compare_first_component (const void *pa, lang_compare_first_component (const char *a,
const void *pb) const char *b)
{ {
const char *a = pa, *b = pb;
unsigned int da, db; unsigned int da, db;
const char *p; const char *p;
...@@ -645,7 +644,7 @@ hb_ot_tag_from_language (hb_language_t language) ...@@ -645,7 +644,7 @@ hb_ot_tag_from_language (hb_language_t language)
/* find a language matching in the first component */ /* find a language matching in the first component */
lang_tag = bsearch (lang_str, ot_languages, lang_tag = bsearch (lang_str, ot_languages,
ARRAY_LENGTH (ot_languages), sizeof (LangTag), ARRAY_LENGTH (ot_languages), sizeof (LangTag),
lang_compare_first_component); (hb_compare_func_t) lang_compare_first_component);
/* we now need to find the best language matching */ /* we now need to find the best language matching */
if (lang_tag) if (lang_tag)
...@@ -654,12 +653,12 @@ hb_ot_tag_from_language (hb_language_t language) ...@@ -654,12 +653,12 @@ hb_ot_tag_from_language (hb_language_t language)
/* go to the final one matching in the first component */ /* go to the final one matching in the first component */
while (lang_tag + 1 < ot_languages + ARRAY_LENGTH (ot_languages) && while (lang_tag + 1 < ot_languages + ARRAY_LENGTH (ot_languages) &&
lang_compare_first_component (lang_str, lang_tag + 1) == 0) lang_compare_first_component (lang_str, (lang_tag + 1)->language) == 0)
lang_tag++; lang_tag++;
/* go back, find which one matches completely */ /* go back, find which one matches completely */
while (lang_tag >= ot_languages && while (lang_tag >= ot_languages &&
lang_compare_first_component (lang_str, lang_tag) == 0) lang_compare_first_component (lang_str, lang_tag->language) == 0)
{ {
if (lang_matches (lang_str, lang_tag->language)) { if (lang_matches (lang_str, lang_tag->language)) {
found = TRUE; found = TRUE;
......
...@@ -186,6 +186,10 @@ _hb_ctz (unsigned int number) ...@@ -186,6 +186,10 @@ _hb_ctz (unsigned int number)
#endif #endif
} }
/* Type of bsearch() / qsort() compare function */
typedef int (*hb_compare_func_t) (const void *, const void *);
/* We need external help for these */ /* We need external help for these */
#ifdef HAVE_GLIB #ifdef HAVE_GLIB
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册