From 130be479cbfc8ce3b710e15e8526a795499046a5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 5 Aug 2022 02:17:55 +0200 Subject: [PATCH] LibGfx: Don't use Span as hash key for cached emojis We can't rely on the caller to keep the code points alive, and this was sometimes causing incorrect cache hits, leading to the wrong emoji being displayed. Fixes #14693 --- Userland/Libraries/LibGfx/Font/Emoji.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/Emoji.cpp b/Userland/Libraries/LibGfx/Font/Emoji.cpp index db4d6be060..08818ae540 100644 --- a/Userland/Libraries/LibGfx/Font/Emoji.cpp +++ b/Userland/Libraries/LibGfx/Font/Emoji.cpp @@ -18,7 +18,7 @@ namespace Gfx { // https://unicode.org/emoji/charts/emoji-list.html // https://unicode.org/emoji/charts/emoji-zwj-sequences.html -static HashMap, RefPtr> s_emojis; +static HashMap> s_emojis; Bitmap const* Emoji::emoji_for_code_point(u32 code_point) { @@ -27,18 +27,20 @@ Bitmap const* Emoji::emoji_for_code_point(u32 code_point) Bitmap const* Emoji::emoji_for_code_points(Span const& code_points) { - auto it = s_emojis.find(code_points); + // FIXME: This function is definitely not fast. + auto basename = String::join('_', code_points, "U+{:X}"sv); + + auto it = s_emojis.find(basename); if (it != s_emojis.end()) return (*it).value.ptr(); - auto basename = String::join('_', code_points, "U+{:X}"sv); auto bitmap_or_error = Bitmap::try_load_from_file(String::formatted("/res/emoji/{}.png", basename)); if (bitmap_or_error.is_error()) { - s_emojis.set(code_points, nullptr); + s_emojis.set(basename, nullptr); return nullptr; } auto bitmap = bitmap_or_error.release_value(); - s_emojis.set(code_points, bitmap); + s_emojis.set(basename, bitmap); return bitmap.ptr(); }