From: Behdad Esfahbod Date: Fri, 8 Oct 2010 23:43:48 +0000 (-0400) Subject: Minor cleanup X-Git-Tag: submit/master/20120920.151126~7^2~518 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8f08c3275040870a645ef034a38d30c05c619f21;p=framework%2Fuifw%2Fharfbuzz.git Minor cleanup --- diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index b83a2e3..ea1d371 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -718,13 +718,9 @@ struct SortedArrayOf : ArrayOf { template inline int search (const SearchType &x) const { class Cmp { - public: static int cmp (const void *p1, const void *p2) { - const SearchType *a = reinterpret_cast(p1); - const Type *b = reinterpret_cast(p2); - return b->cmp (*a); - } + public: static int cmp (const SearchType *a, const Type *b) { 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; } }; diff --git a/src/hb-ot-map-private.hh b/src/hb-ot-map-private.hh index 786a0d0..2d790b0 100644 --- a/src/hb-ot-map-private.hh +++ b/src/hb-ot-map-private.hh @@ -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 { + private: + struct feature_info_t { hb_tag_t tag; unsigned int value; unsigned int seq; bool global; - static int - cmp (const void *p1, const void *p2) - { - const feature_info_t *a = reinterpret_cast(p1); - const feature_info_t *b = reinterpret_cast(p2); - - if (a->tag != b->tag) - return a->tag < b->tag ? -1 : 1; - - return a->seq < b->seq ? -1 : 1; - } + static int cmp (const feature_info_t *a, const feature_info_t *b) + { return (a->tag != b->tag) ? (a->tag < b->tag ? -1 : 1) : (a->seq < b->seq ? -1 : 1); } }; struct feature_map_t { @@ -68,28 +61,16 @@ struct hb_mask_allocator_t { unsigned int shift; hb_mask_t mask; - static int - cmp (const void *p1, const void *p2) - { - const feature_map_t *a = reinterpret_cast(p1); - const feature_map_t *b = reinterpret_cast(p2); - - return a->tag < b->tag ? -1 : a->tag > b->tag ? 1 : 0; - } + static int cmp (const feature_map_t *a, const feature_map_t *b) + { return a->tag < b->tag ? -1 : a->tag > b->tag ? 1 : 0; } }; struct lookup_map_t { unsigned int index; hb_mask_t mask; - static int - cmp (const void *p1, const void *p2) - { - const lookup_map_t *a = reinterpret_cast(p1); - const lookup_map_t *b = reinterpret_cast(p2); - - return a->index < b->index ? -1 : a->index > b->index ? 1 : 0; - } + static int cmp (const lookup_map_t *a, const lookup_map_t *b) + { return a->index < b->index ? -1 : a->index > b->index ? 1 : 0; } }; @@ -120,6 +101,7 @@ struct hb_mask_allocator_t { + public: hb_mask_allocator_t (void) : feature_count (0) {} @@ -160,10 +142,8 @@ struct hb_mask_allocator_t { } - /* Sort the features so we can bsearch later */ - qsort (feature_infos, feature_count, sizeof (feature_infos[0]), feature_info_t::cmp); - - /* Remove dups, let later-occurring features override earlier ones. */ + /* Sort features and merge duplicates */ + qsort (feature_infos, feature_count, sizeof (feature_infos[0]), (hb_compare_func_t) feature_info_t::cmp); unsigned int j = 0; for (unsigned int i = 1; i < feature_count; i++) if (feature_infos[i].tag != feature_infos[j].tag) @@ -248,9 +228,7 @@ struct hb_mask_allocator_t { add_lookups (c, 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]), lookup_map_t::cmp); - + 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]) { unsigned int j = 0; @@ -268,22 +246,17 @@ struct hb_mask_allocator_t { hb_mask_t get_global_mask (void) { return global_mask; } 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); - if (likely (map)) { - if (shift) *shift = map->shift; - return map->mask; - } else { - if (shift) *shift = 0; - return 0; - } + 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 (shift) *shift = map ? map->shift : 0; + return map ? map->mask : 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++) 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++) hb_ot_layout_position_lookup (c->font, c->face, c->buffer, lookup_maps[1][i].index, lookup_maps[1][i].mask); } diff --git a/src/hb-ot-tag.c b/src/hb-ot-tag.c index 448f795..32d455d 100644 --- a/src/hb-ot-tag.c +++ b/src/hb-ot-tag.c @@ -591,10 +591,9 @@ static const LangTag ot_languages[] = { }; static int -lang_compare_first_component (const void *pa, - const void *pb) +lang_compare_first_component (const char *a, + const char *b) { - const char *a = pa, *b = pb; unsigned int da, db; const char *p; @@ -645,7 +644,7 @@ hb_ot_tag_from_language (hb_language_t language) /* find a language matching in the first component */ lang_tag = bsearch (lang_str, ot_languages, 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 */ if (lang_tag) @@ -654,12 +653,12 @@ hb_ot_tag_from_language (hb_language_t language) /* go to the final one matching in the first component */ 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++; /* go back, find which one matches completely */ 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)) { found = TRUE; diff --git a/src/hb-private.h b/src/hb-private.h index ad7c362..1d4cfc9 100644 --- a/src/hb-private.h +++ b/src/hb-private.h @@ -186,6 +186,10 @@ _hb_ctz (unsigned int number) #endif } +/* Type of bsearch() / qsort() compare function */ +typedef int (*hb_compare_func_t) (const void *, const void *); + + /* We need external help for these */ #ifdef HAVE_GLIB