From 6d97caf124ffca77dd3b829dfef3de55f073c62e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 7 Aug 2019 11:57:51 +0200 Subject: [PATCH] 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. --- AK/JsonParser.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp index 29f4f81755..983d99fbd9 100644 --- a/AK/JsonParser.cpp +++ b/AK/JsonParser.cpp @@ -45,8 +45,24 @@ String JsonParser::consume_quoted_string() { consume_specific('"'); Vector 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(); } - }