mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 12:49:19 +00:00
LibGfx: Let FontCascadeList quickly reject out-of-range code points
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
By keeping track of the enclosing range around all Unicode ranges of a FontCascadeList entry, we can quickly reject any code point that's outside all ranges. This knocks font_for_code_point() from 7% to 3% in the profile when scrolling on https://screenshotone.com/
This commit is contained in:
parent
488333aa4b
commit
0fece0650e
Notes:
github-actions[bot]
2025-07-14 22:54:07 +00:00
Author: https://github.com/awesomekling
Commit: 0fece0650e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5442
2 changed files with 24 additions and 4 deletions
|
@ -15,7 +15,19 @@ void FontCascadeList::add(NonnullRefPtr<Font const> font)
|
|||
|
||||
void FontCascadeList::add(NonnullRefPtr<Font const> font, Vector<UnicodeRange> unicode_ranges)
|
||||
{
|
||||
m_fonts.append({ move(font), move(unicode_ranges) });
|
||||
u32 lowest_code_point = 0xFFFFFFFF;
|
||||
u32 highest_code_point = 0;
|
||||
|
||||
for (auto& range : unicode_ranges) {
|
||||
lowest_code_point = min(lowest_code_point, range.min_code_point());
|
||||
highest_code_point = max(highest_code_point, range.max_code_point());
|
||||
}
|
||||
|
||||
m_fonts.append({ move(font),
|
||||
Entry::RangeData {
|
||||
{ lowest_code_point, highest_code_point },
|
||||
move(unicode_ranges),
|
||||
} });
|
||||
}
|
||||
|
||||
void FontCascadeList::extend(FontCascadeList const& other)
|
||||
|
@ -26,8 +38,10 @@ void FontCascadeList::extend(FontCascadeList const& other)
|
|||
Gfx::Font const& FontCascadeList::font_for_code_point(u32 code_point) const
|
||||
{
|
||||
for (auto const& entry : m_fonts) {
|
||||
if (entry.unicode_ranges.has_value()) {
|
||||
for (auto const& range : *entry.unicode_ranges) {
|
||||
if (entry.range_data.has_value()) {
|
||||
if (!entry.range_data->enclosing_range.contains(code_point))
|
||||
continue;
|
||||
for (auto const& range : entry.range_data->unicode_ranges) {
|
||||
if (range.contains(code_point) && entry.font->contains_glyph(code_point))
|
||||
return entry.font;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue