From 0b97ac39ac0bbe4d0027d1bb96668f456aaf634b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 6 Feb 2023 15:17:09 -0700 Subject: [PATCH] [buffer] Optimize _infos_find_min_cluster for monotone clusters --- src/hb-buffer.hh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index 6f45900e8..d278022d7 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -588,14 +588,22 @@ struct hb_buffer_t infos[i].mask |= mask; } } - static unsigned + unsigned _infos_find_min_cluster (const hb_glyph_info_t *infos, unsigned start, unsigned end, unsigned cluster = UINT_MAX) { - for (unsigned int i = start; i < end; i++) - cluster = hb_min (cluster, infos[i].cluster); - return cluster; + if (unlikely (start == end)) + return cluster; + + if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS) + { + for (unsigned int i = start; i < end; i++) + cluster = hb_min (cluster, infos[i].cluster); + return cluster; + } + + return hb_min (cluster, hb_min (infos[start].cluster, infos[end - 1].cluster)); } void clear_glyph_flags (hb_mask_t mask = 0)