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)
This commit is contained in:
Andreas Kling 2024-09-10 10:10:44 +02:00 committed by Andreas Kling
parent 84ec690d90
commit 80e37db280
Notes: github-actions[bot] 2024-09-10 09:04:37 +00:00
2 changed files with 8 additions and 3 deletions

View file

@ -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

View file

@ -39,6 +39,8 @@ private:
ReadonlyBytes m_buffer;
unsigned m_ttc_index { 0 };
mutable Optional<String> m_family;
// This cache stores information per code point.
// It's segmented into pages with data about 256 code points each.
struct GlyphPage {