From 0d0230ab10b123584431aab07a807697982b44c9 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 4 Aug 2019 20:23:03 +0200 Subject: JsonParser: Fold extract_while() into parse_number() It wasn't unsed anywhere else anyway, and this is actually ~1% faster on the load_4chan_catalog benchmark. --- AK/JsonParser.cpp | 21 +++++++++++---------- AK/JsonParser.h | 3 --- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'AK') diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp index b50c89d356..29f4f81755 100644 --- a/AK/JsonParser.cpp +++ b/AK/JsonParser.cpp @@ -30,15 +30,6 @@ void JsonParser::consume_while(C condition) consume(); } -template -Vector JsonParser::extract_while(C condition) -{ - Vector buffer; - while (condition(peek())) - buffer.append(consume()); - return buffer; -}; - void JsonParser::consume_whitespace() { consume_while([](char ch) { return is_whitespace(ch); }); @@ -156,7 +147,17 @@ JsonValue JsonParser::parse_string() JsonValue JsonParser::parse_number() { - auto number_buffer = extract_while([](char ch) { return ch == '-' || (ch >= '0' && ch <= '9'); }); + Vector number_buffer; + for (;;) { + char ch = peek(); + if (ch == '-' || (ch >= '0' && ch <= '9')) { + number_buffer.append(ch); + ++m_index; + continue; + } + break; + } + StringView number_string(number_buffer.data(), number_buffer.size()); bool ok; auto value = JsonValue(number_string.to_uint(ok)); diff --git a/AK/JsonParser.h b/AK/JsonParser.h index 26756abf36..7a65d1c638 100644 --- a/AK/JsonParser.h +++ b/AK/JsonParser.h @@ -35,9 +35,6 @@ private: template void consume_while(C); - template - Vector extract_while(C); - StringView m_input; int m_index { 0 }; -- cgit v1.2.3