mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
JsonParser: Scan ahead to find the first special char in quoted strings
This allows us to take advantage of the now-optimized (to do memmove()) Vector::append(const T*, int count) for collecting these strings. This is a ~15% speedup on the load_4chan_catalog benchmark.
This commit is contained in:
parent
b48b6c0caa
commit
6d97caf124
Notes:
sideshowbarker
2024-07-19 12:50:43 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6d97caf124f
1 changed files with 17 additions and 2 deletions
|
@ -45,8 +45,24 @@ String JsonParser::consume_quoted_string()
|
|||
{
|
||||
consume_specific('"');
|
||||
Vector<char, 1024> buffer;
|
||||
|
||||
for (;;) {
|
||||
char ch = peek();
|
||||
int peek_index = m_index;
|
||||
char ch = 0;
|
||||
for (;;) {
|
||||
if (peek_index == m_input.length())
|
||||
break;
|
||||
ch = m_input[peek_index];
|
||||
if (ch == '"' || ch == '\\')
|
||||
break;
|
||||
++peek_index;
|
||||
}
|
||||
|
||||
if (peek_index != m_index) {
|
||||
buffer.append(m_input.characters_without_null_termination() + m_index, peek_index - m_index);
|
||||
m_index = peek_index;
|
||||
}
|
||||
|
||||
if (ch == '"')
|
||||
break;
|
||||
if (ch != '\\') {
|
||||
|
@ -232,5 +248,4 @@ JsonValue JsonParser::parse()
|
|||
|
||||
return JsonValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue