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:
Andreas Kling 2019-08-07 11:57:51 +02:00
parent b48b6c0caa
commit 6d97caf124
Notes: sideshowbarker 2024-07-19 12:50:43 +09:00

View file

@ -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();
}
}