From 86b702250361485f0d57dcf6fe4a38eaacf0d87e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 26 Jun 2022 16:56:24 -0600 Subject: [PATCH] [glyf] Optimize flag decoding --- src/OT/glyf/SimpleGlyph.hh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/OT/glyf/SimpleGlyph.hh b/src/OT/glyf/SimpleGlyph.hh index 0d49d5cdc..34502dbd5 100644 --- a/src/OT/glyf/SimpleGlyph.hh +++ b/src/OT/glyf/SimpleGlyph.hh @@ -170,17 +170,18 @@ struct SimpleGlyph endPtsOfContours[num_contours]); /* Read flags */ - for (unsigned int i = 0; i < num_points; i++) + for (unsigned int i = 0; i < num_points;) { if (unlikely (!bytes.check_range (p))) return false; uint8_t flag = *p++; - points_[i].flag = flag; + points_[i++].flag = flag; if (flag & FLAG_REPEAT) { if (unlikely (!bytes.check_range (p))) return false; unsigned int repeat_count = *p++; - while ((repeat_count-- > 0) && (++i < num_points)) - points_[i].flag = flag; + unsigned stop = hb_min (i + repeat_count, num_points); + for (; i < stop;) + points_.arrayZ[i++].flag = flag; } }