提交 99159e52 编写于 作者: B Behdad Esfahbod

Use linear search for small counts

I see about 8% speedup with long strings with DejaVu Sans.
上级 caf04126
...@@ -698,11 +698,20 @@ struct SortedArrayOf : ArrayOf<Type> { ...@@ -698,11 +698,20 @@ struct SortedArrayOf : ArrayOf<Type> {
template <typename SearchType> template <typename SearchType>
inline int search (const SearchType &x) const { inline int search (const SearchType &x) const {
struct Cmp { unsigned int count = this->len;
static int cmp (const SearchType *a, const Type *b) { return b->cmp (*a); } /* Linear search is *much* faster for small counts. */
}; if (likely (count < 32)) {
const Type *p = (const Type *) bsearch (&x, this->array, this->len, sizeof (this->array[0]), (hb_compare_func_t) Cmp::cmp); for (unsigned int i = 0; i < count; i++)
return p ? p - this->array : -1; if (this->array[i].cmp (x) == 0)
return i;
return -1;
} else {
struct Cmp {
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]), (hb_compare_func_t) Cmp::cmp);
return p ? p - this->array : -1;
}
} }
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册