From 7cd975268c377f5347ce2a6f84803892b2108e58 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 24 Aug 2023 11:35:54 +0200 Subject: [PATCH] LibWeb: Use Gfx::FontDatabase::for_each_typeface_with_family_name() This avoids looking at every single installed typeface to see if there's a family name match. Fixes a large performance regression introduced when making StyleComputer consider system fonts in CSS font fallback. Regressed with 69a81243f5a602e5994258bc10af132f008d5858. --- .../Libraries/LibWeb/CSS/StyleComputer.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 40dad4019d..0c9f1c8dae 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -2077,16 +2077,14 @@ RefPtr StyleComputer::font_matching_algorithm(FontFaceKey const if (font_key_and_loader.key.family_name.equals_ignoring_ascii_case(key.family_name)) matching_family_fonts.empend(font_key_and_loader.key, font_key_and_loader.value.ptr()); } - Gfx::FontDatabase::the().for_each_typeface([&](Gfx::Typeface const& typeface) { - if (typeface.family().equals_ignoring_ascii_case(key.family_name)) { - matching_family_fonts.empend( - FontFaceKey { - .family_name = MUST(FlyString::from_deprecated_fly_string(typeface.family())), - .weight = static_cast(typeface.weight()), - .slope = typeface.slope(), - }, - &typeface); - } + Gfx::FontDatabase::the().for_each_typeface_with_family_name(key.family_name.to_string(), [&](Gfx::Typeface const& typeface) { + matching_family_fonts.empend( + FontFaceKey { + .family_name = MUST(FlyString::from_deprecated_fly_string(typeface.family())), + .weight = static_cast(typeface.weight()), + .slope = typeface.slope(), + }, + &typeface); }); quick_sort(matching_family_fonts, [](auto const& a, auto const& b) { return a.key.weight < b.key.weight;