From 0fe90ebc00d07a1a636ed0dfdd72f5586b51bcfa Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 3 May 2023 12:49:31 -0600 Subject: [PATCH] [Ligature] Micro-optimize --- src/OT/Layout/GSUB/LigatureSet.hh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/OT/Layout/GSUB/LigatureSet.hh b/src/OT/Layout/GSUB/LigatureSet.hh index b9a89e568..2aac8539d 100644 --- a/src/OT/Layout/GSUB/LigatureSet.hh +++ b/src/OT/Layout/GSUB/LigatureSet.hh @@ -109,20 +109,28 @@ struct LigatureSet } bool not_short_circuit = matched && skippy_iter.may_skip (c->buffer->info[skippy_iter.idx]); + bool unsafe_to_concat = false; unsigned int num_ligs = ligature.len; for (unsigned int i = 0; i < num_ligs; i++) { const auto &lig = this+ligature.arrayZ[i]; - if (lig.component.lenP1 <= 1 || + if (unlikely (lig.component.lenP1 <= 1) || lig.component[1] == first || not_short_circuit) { - if (lig.apply (c)) return_trace (true); + if (lig.apply (c)) + { + if (unsafe_to_concat) + c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to); + return_trace (true); + } } - else if (lig.component.lenP1 > 1) - c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to); + else if (likely (lig.component.lenP1 > 1)) + unsafe_to_concat = true; } + if (likely (unsafe_to_concat)) + c->buffer->unsafe_to_concat (c->buffer->idx, unsafe_to); return_trace (false); }