diff --git a/src/hb-array.hh b/src/hb-array.hh index 1d1476d7c..fc6e52b1d 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -352,14 +352,15 @@ struct hb_sorted_array_t : unsigned int i; return bfind (x, &i) ? &this->arrayZ[i] : not_found; } - template + template bool bfind (const T &x, unsigned int *i = nullptr, hb_not_found_t not_found = HB_NOT_FOUND_DONT_STORE, - unsigned int to_store = (unsigned int) -1) const + unsigned int to_store = (unsigned int) -1, + Ts... ds) const { unsigned pos; - if (bsearch_impl (x, &pos)) + if (bsearch_impl (x, &pos, ds...)) { if (i) *i = pos; @@ -384,15 +385,16 @@ struct hb_sorted_array_t : } return false; } - template - bool bsearch_impl (const T &x, unsigned *pos) const + template + bool bsearch_impl (const T &x, unsigned *pos, Ts... ds) const { return hb_bsearch_impl (pos, x, this->arrayZ, this->length, sizeof (Type), - _hb_cmp_method); + _hb_cmp_method, + ds...); } }; template inline hb_sorted_array_t diff --git a/src/hb-ot-tag.cc b/src/hb-ot-tag.cc index 22df9bf29..31dd7c544 100644 --- a/src/hb-ot-tag.cc +++ b/src/hb-ot-tag.cc @@ -219,22 +219,13 @@ struct LangTag char language[4]; hb_tag_t tag; - int cmp (const char *a) const + int cmp (const char *a, unsigned len) const { const char *b = this->language; - unsigned int da, db; - const char *p; - - p = strchr (a, '-'); - da = p ? (unsigned int) (p - a) : strlen (a); - - p = strchr (b, '-'); - db = p ? (unsigned int) (p - b) : strlen (b); - - return strncmp (a, b, hb_max (da, db)); + return strncmp (a, b, len); } int cmp (const LangTag *that) const - { return cmp (that->language); } + { return cmp (that->language, strlen (that->language)); } }; #include "hb-ot-tag-table.hh" @@ -298,7 +289,9 @@ hb_ot_tags_from_language (const char *lang_str, ot_languages = ot_languages3; ot_languages_len = ARRAY_LENGTH (ot_languages3); } - if (hb_sorted_array (ot_languages, ot_languages_len).bfind (lang_str, &tag_idx)) + if (hb_sorted_array (ot_languages, ot_languages_len).bfind (lang_str, &tag_idx, + HB_NOT_FOUND_DONT_STORE, (unsigned) -1, + first_len)) { unsigned int i; while (tag_idx != 0 &&