[HarfBuzz] harfbuzz: Branch 'master' - 2 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Fri Apr 19 11:42:42 PDT 2013
src/hb-open-type-private.hh | 29 +++++++++++++++--------------
src/hb-ot-layout-common-private.hh | 3 +--
2 files changed, 16 insertions(+), 16 deletions(-)
New commits:
commit 8659c636087e433f56da458351e8b4d85fdb347c
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Fri Apr 19 14:33:17 2013 -0400
Hand-code bsearch in the hot inner loop.
Saves another 3 / 4 percent with Amiri.
diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index cd1163e..6a8b98b 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -949,21 +949,22 @@ template <typename Type>
struct SortedArrayOf : ArrayOf<Type> {
template <typename SearchType>
- inline int search (const SearchType &x) const {
- unsigned int count = this->len;
- /* Linear search is *much* faster for small counts. */
- if (likely (count < 32)) {
- for (unsigned int i = 0; i < count; i++)
- 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;
+ inline int search (const SearchType &x) const
+ {
+ /* Hand-coded bsearch here since this is in the hot inner loop. */
+ int min = 0, max = (int) this->len - 1;
+ while (min <= max)
+ {
+ int mid = (min + max) / 2;
+ int c = this->array[mid].cmp (x);
+ if (c < 0)
+ max = mid - 1;
+ else if (c > 0)
+ min = mid + 1;
+ else
+ return mid;
}
+ return -1;
}
};
commit 797d76d07f80d796a825d850772087104e5a2575
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Thu Apr 18 19:04:12 2013 -0400
Minor
diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh
index e6018db..d139b56 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -129,8 +129,7 @@ struct RecordListOf : RecordArrayOf<Type>
struct RangeRecord
{
inline int cmp (hb_codepoint_t g) const {
- hb_codepoint_t a = start, b = end;
- return g < a ? -1 : g <= b ? 0 : +1 ;
+ return g < start ? -1 : g <= end ? 0 : +1 ;
}
inline bool sanitize (hb_sanitize_context_t *c) {
More information about the HarfBuzz
mailing list