From 80e37db280fa21e1c6e99f8107dcb4d29bca4094 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 10 Sep 2024 10:10:44 +0200 Subject: [PATCH] LibGfx: Cache the family name in TypefaceSkia Instead of asking Skia for the family name every time we're called, just cache the string once and make subsequent calls fast. This knocks a 3.2% item off the profile entirely on https://tailwindcss.com (at least on macOS with the CoreText backend) --- Userland/Libraries/LibGfx/Font/TypefaceSkia.cpp | 9 ++++++--- Userland/Libraries/LibGfx/Font/TypefaceSkia.h | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/TypefaceSkia.cpp b/Userland/Libraries/LibGfx/Font/TypefaceSkia.cpp index b568194820e..293eb7e9456 100644 --- a/Userland/Libraries/LibGfx/Font/TypefaceSkia.cpp +++ b/Userland/Libraries/LibGfx/Font/TypefaceSkia.cpp @@ -116,9 +116,12 @@ void TypefaceSkia::populate_glyph_page(GlyphPage& glyph_page, size_t page_index) String TypefaceSkia::family() const { - SkString family_name; - impl().skia_typeface->getFamilyName(&family_name); - return String::from_utf8_without_validation(ReadonlyBytes { family_name.c_str(), family_name.size() }); + if (!m_family.has_value()) { + SkString family_name; + impl().skia_typeface->getFamilyName(&family_name); + m_family = String::from_utf8_without_validation(ReadonlyBytes { family_name.c_str(), family_name.size() }); + } + return m_family.value(); } u16 TypefaceSkia::weight() const diff --git a/Userland/Libraries/LibGfx/Font/TypefaceSkia.h b/Userland/Libraries/LibGfx/Font/TypefaceSkia.h index e4b7312db4f..567857c2109 100644 --- a/Userland/Libraries/LibGfx/Font/TypefaceSkia.h +++ b/Userland/Libraries/LibGfx/Font/TypefaceSkia.h @@ -39,6 +39,8 @@ private: ReadonlyBytes m_buffer; unsigned m_ttc_index { 0 }; + mutable Optional m_family; + // This cache stores information per code point. // It's segmented into pages with data about 256 code points each. struct GlyphPage {