mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
LibJS: Add ASCII fast path to Lexer::current_code_point()
If the current character under the lexer cursor is ASCII, we don't need to create a Utf8View to consume a full code point. This gives a ~3% speedup when parsing the largest Discord JS file.
This commit is contained in:
parent
c74b6c06a5
commit
3d9f2e2f94
Notes:
sideshowbarker
2024-07-17 18:55:52 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3d9f2e2f94
1 changed files with 5 additions and 2 deletions
|
@ -363,9 +363,12 @@ u32 Lexer::current_code_point() const
|
|||
static constexpr const u32 REPLACEMENT_CHARACTER = 0xFFFD;
|
||||
if (m_position == 0)
|
||||
return REPLACEMENT_CHARACTER;
|
||||
Utf8View utf_8_view { m_source.substring_view(m_position - 1) };
|
||||
if (utf_8_view.is_empty())
|
||||
auto substring = m_source.substring_view(m_position - 1);
|
||||
if (substring.is_empty())
|
||||
return REPLACEMENT_CHARACTER;
|
||||
if (is_ascii(substring[0]))
|
||||
return substring[0];
|
||||
Utf8View utf_8_view { substring };
|
||||
return *utf_8_view.begin();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue