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 69a81243f5.
This commit is contained in:
Andreas Kling 2023-08-24 11:35:54 +02:00
parent 2cd89531f9
commit 7cd975268c
Notes: sideshowbarker 2024-07-17 00:53:02 +09:00

View file

@ -2077,16 +2077,14 @@ RefPtr<Gfx::Font const> 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<int>(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<int>(typeface.weight()),
.slope = typeface.slope(),
},
&typeface);
});
quick_sort(matching_family_fonts, [](auto const& a, auto const& b) {
return a.key.weight < b.key.weight;