summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-02-13 12:44:57 +0100
committerAndreas Kling <kling@serenityos.org>2022-02-13 14:44:36 +0100
commit3d9f2e2f94074e1705b5fe3a5fefa95ee669fdb5 (patch)
treeb935c7156dcb8bb97065fdf1210cfe56b025962a /Userland
parentc74b6c06a55cb7c15b586538a44d1017f2a33c78 (diff)
downloadserenity-3d9f2e2f94074e1705b5fe3a5fefa95ee669fdb5.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Lexer.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Lexer.cpp b/Userland/Libraries/LibJS/Lexer.cpp
index 685e915d2b..43a3952a56 100644
--- a/Userland/Libraries/LibJS/Lexer.cpp
+++ b/Userland/Libraries/LibJS/Lexer.cpp
@@ -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();
}