From 4ea3737d04c575cd9b6ffda1e4e0f2c9d2b60d9c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 17 Jul 2023 09:50:28 -0600 Subject: [PATCH] [gsubgpos] Add fast-path for end-of-string in (Chain)RuleSet::apply() --- src/hb-ot-layout-gsubgpos.hh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index f9e7e3d74..549d12999 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -2204,7 +2204,18 @@ struct RuleSet } } else - goto slow; + { + /* Failed to match a next glyph. Only try applying rules that have + * no further input. */ + return_trace ( + + hb_iter (rule) + | hb_map (hb_add (this)) + | hb_filter ([&] (const Rule &_) { return _.inputCount <= 1; }) + | hb_map ([&] (const Rule &_) { return _.apply (c, lookup_context); }) + | hb_any + ) + ; + } bool unsafe_to_concat = false; @@ -3346,7 +3357,18 @@ struct ChainRuleSet } } else - goto slow; + { + /* Failed to match a next glyph. Only try applying rules that have + * no further input and lookahead. */ + return_trace ( + + hb_iter (rule) + | hb_map (hb_add (this)) + | hb_filter ([&] (const ChainRule &_) { return _.inputX.lenP1 <= 1 && _.lookaheadX.len == 0; }) + | hb_map ([&] (const ChainRule &_) { return _.apply (c, lookup_context); }) + | hb_any + ) + ; + } bool unsafe_to_concat = false;