summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx
diff options
context:
space:
mode:
authorMax Wipfli <mail@maxwipfli.ch>2021-07-09 13:40:39 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-09 20:17:07 +0200
commit006e5998c51f729a422e704c0575006c806b1b39 (patch)
treef22de70f5345ee6ad0c37dc5557ec518fe428b2f /Userland/Libraries/LibGfx
parent4578ab3ed04169dcfeb5152c10202d0b8c4175e7 (diff)
downloadserenity-006e5998c51f729a422e704c0575006c806b1b39.zip
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.
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r--Userland/Libraries/LibGfx/BitmapFont.cpp5
1 files 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;
}