From e92eefaabbed7aa04fe98214ae43b061d1497735 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 2 Jul 2023 11:35:51 -0600 Subject: [PATCH] [gvar] Cache two values in shared_tuple_active_idx Speeds up varc-hangul.ttf draw_glyph by 10%. --- src/hb-ot-var-common.hh | 17 ++++++++++++----- src/hb-ot-var-gvar-table.hh | 15 +++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index c28962103..44ec64bc0 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -300,12 +300,13 @@ struct TupleVariationHeader float calculate_scalar (hb_array_t coords, unsigned int coord_count, const hb_array_t shared_tuples, - const hb_vector_t *shared_tuple_active_idx = nullptr) const + const hb_vector_t> *shared_tuple_active_idx = nullptr) const { const F2DOT14 *peak_tuple; unsigned start_idx = 0; unsigned end_idx = coord_count; + unsigned step = 1; if (has_peak ()) peak_tuple = get_peak_tuple (coord_count).arrayZ; @@ -320,10 +321,16 @@ struct TupleVariationHeader { if (unlikely (index >= shared_tuple_active_idx->length)) return 0.f; - int v = (*shared_tuple_active_idx).arrayZ[index]; - if (v != -1) + auto _ = (*shared_tuple_active_idx).arrayZ[index]; + if (_.second != -1) { - start_idx = v; + start_idx = _.first; + end_idx = _.second + 1; + step = _.second - _.first; + } + else if (_.first != -1) + { + start_idx = _.first; end_idx = start_idx + 1; } } @@ -339,7 +346,7 @@ struct TupleVariationHeader } float scalar = 1.f; - for (unsigned int i = start_idx; i < end_idx; i++) + for (unsigned int i = start_idx; i < end_idx; i += step) { int peak = peak_tuple[i].to_int (); if (!peak) continue; diff --git a/src/hb-ot-var-gvar-table.hh b/src/hb-ot-var-gvar-table.hh index fc8ae2333..b5099ac07 100644 --- a/src/hb-ot-var-gvar-table.hh +++ b/src/hb-ot-var-gvar-table.hh @@ -242,21 +242,24 @@ struct gvar for (unsigned i = 0; i < count; i++) { hb_array_t tuple = shared_tuples.sub_array (axis_count * i, axis_count); - int idx = -1; + int idx1 = -1, idx2 = -1; for (unsigned j = 0; j < axis_count; j++) { const F2DOT14 &peak = tuple.arrayZ[j]; if (peak.to_int () != 0) { - if (idx != -1) + if (idx1 == -1) + idx1 = j; + else if (idx2 == -1) + idx2 = j; + else { - idx = -1; + idx1 = idx2 = -1; break; } - idx = j; } } - shared_tuple_active_idx.arrayZ[i] = idx; + shared_tuple_active_idx.arrayZ[i] = {idx1, idx2}; } } ~accelerator_t () { table.destroy (); } @@ -523,7 +526,7 @@ struct gvar private: hb_blob_ptr_t table; unsigned glyphCount; - hb_vector_t shared_tuple_active_idx; + hb_vector_t> shared_tuple_active_idx; }; protected: