mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +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
1 changed files with 17 additions and 2 deletions
|
@ -45,8 +45,24 @@ String JsonParser::consume_quoted_string()
|
||||||
{
|
{
|
||||||
consume_specific('"');
|
consume_specific('"');
|
||||||
Vector<char, 1024> buffer;
|
Vector<char, 1024> buffer;
|
||||||
|
|
||||||
for (;;) {
|
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 == '"')
|
if (ch == '"')
|
||||||
break;
|
break;
|
||||||
if (ch != '\\') {
|
if (ch != '\\') {
|
||||||
|
@ -232,5 +248,4 @@ JsonValue JsonParser::parse()
|
||||||
|
|
||||||
return JsonValue();
|
return JsonValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue