LibGfx: Optimize BitmapFont::unicode_view_width() a bit

This optimizes the method to no longer compare if width > longest_width
on every iteration, since it's only required on CR/LF or at the end.
This commit is contained in:
Max Wipfli 2021-07-09 13:40:39 +02:00 committed by Andreas Kling
parent 4578ab3ed0
commit 006e5998c5
Notes: sideshowbarker 2024-07-18 09:58:53 +09:00

View file

@ -264,6 +264,7 @@ ALWAYS_INLINE int BitmapFont::unicode_view_width(T const& view) const
for (u32 code_point : view) {
if (code_point == '\n' || code_point == '\r') {
first = true;
longest_width = max(width, longest_width);
width = 0;
continue;
}
@ -271,10 +272,8 @@ ALWAYS_INLINE int BitmapFont::unicode_view_width(T const& view) const
width += glyph_spacing();
first = false;
width += glyph_or_emoji_width(code_point);
if (width > longest_width)
longest_width = width;
}
longest_width = max(width, longest_width);
return longest_width;
}