From 006e5998c51f729a422e704c0575006c806b1b39 Mon Sep 17 00:00:00 2001 From: Max Wipfli Date: Fri, 9 Jul 2021 13:40:39 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibGfx/BitmapFont.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGfx/BitmapFont.cpp b/Userland/Libraries/LibGfx/BitmapFont.cpp index c89a620577..c84636879a 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/BitmapFont.cpp @@ -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; }