179456c69Sopenharmony_ciFrom 85be877925ddbf34f74a1229f3ca1716bb6170dc Mon Sep 17 00:00:00 2001 279456c69Sopenharmony_ciFrom: Behdad Esfahbod <behdad@behdad.org> 379456c69Sopenharmony_ciDate: Wed, 1 Feb 2023 20:00:43 -0700 479456c69Sopenharmony_ciSubject: [PATCH] [layout] Limit how far we skip when looking back 579456c69Sopenharmony_ci 679456c69Sopenharmony_ciSee comments. 779456c69Sopenharmony_ci--- 879456c69Sopenharmony_ci src/hb-ot-layout-gsubgpos.hh | 12 +++++++++++- 979456c69Sopenharmony_ci 1 file changed, 11 insertions(+), 1 deletion(-) 1079456c69Sopenharmony_ci 1179456c69Sopenharmony_cidiff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh 1279456c69Sopenharmony_ciindex c17bf92..712e307 100644 1379456c69Sopenharmony_ci--- a/src/hb-ot-layout-gsubgpos.hh 1479456c69Sopenharmony_ci+++ b/src/hb-ot-layout-gsubgpos.hh 1579456c69Sopenharmony_ci@@ -535,7 +535,19 @@ struct hb_ot_apply_context_t : 1679456c69Sopenharmony_ci bool prev () 1779456c69Sopenharmony_ci { 1879456c69Sopenharmony_ci assert (num_items > 0); 1979456c69Sopenharmony_ci- while (idx > num_items - 1) 2079456c69Sopenharmony_ci+ /* The alternate condition below is faster at string boundaries, 2179456c69Sopenharmony_ci+ * but produces subpar "unsafe-to-concat" values. */ 2279456c69Sopenharmony_ci+ unsigned stop = num_items - 1; 2379456c69Sopenharmony_ci+ if (c->buffer->flags & HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT) 2479456c69Sopenharmony_ci+ stop = 1 - 1; 2579456c69Sopenharmony_ci+ 2679456c69Sopenharmony_ci+ /* When looking back, limit how far we search; this function is mostly 2779456c69Sopenharmony_ci+ * used for looking back for base glyphs when attaching marks. If we 2879456c69Sopenharmony_ci+ * don't limit, we can get O(n^2) behavior where n is the number of 2979456c69Sopenharmony_ci+ * consecutive marks. */ 3079456c69Sopenharmony_ci+ stop = (unsigned) hb_max ((int) stop, (int) idx - HB_MAX_CONTEXT_LENGTH); 3179456c69Sopenharmony_ci+ 3279456c69Sopenharmony_ci+ while (idx > stop) 3379456c69Sopenharmony_ci { 3479456c69Sopenharmony_ci idx--; 3579456c69Sopenharmony_ci const hb_glyph_info_t &info = c->buffer->out_info[idx]; 3679456c69Sopenharmony_ci-- 3779456c69Sopenharmony_ci2.33.0 3879456c69Sopenharmony_ci 39