mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
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.
This commit is contained in:
parent
a846ee76ea
commit
0d0230ab10
Notes:
sideshowbarker
2024-07-19 12:53:32 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/0d0230ab10b
2 changed files with 11 additions and 13 deletions
|
@ -30,15 +30,6 @@ void JsonParser::consume_while(C condition)
|
||||||
consume();
|
consume();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename C>
|
|
||||||
Vector<char, 128> JsonParser::extract_while(C condition)
|
|
||||||
{
|
|
||||||
Vector<char, 128> buffer;
|
|
||||||
while (condition(peek()))
|
|
||||||
buffer.append(consume());
|
|
||||||
return buffer;
|
|
||||||
};
|
|
||||||
|
|
||||||
void JsonParser::consume_whitespace()
|
void JsonParser::consume_whitespace()
|
||||||
{
|
{
|
||||||
consume_while([](char ch) { return is_whitespace(ch); });
|
consume_while([](char ch) { return is_whitespace(ch); });
|
||||||
|
@ -156,7 +147,17 @@ JsonValue JsonParser::parse_string()
|
||||||
|
|
||||||
JsonValue JsonParser::parse_number()
|
JsonValue JsonParser::parse_number()
|
||||||
{
|
{
|
||||||
auto number_buffer = extract_while([](char ch) { return ch == '-' || (ch >= '0' && ch <= '9'); });
|
Vector<char, 128> 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());
|
StringView number_string(number_buffer.data(), number_buffer.size());
|
||||||
bool ok;
|
bool ok;
|
||||||
auto value = JsonValue(number_string.to_uint(ok));
|
auto value = JsonValue(number_string.to_uint(ok));
|
||||||
|
|
|
@ -35,9 +35,6 @@ private:
|
||||||
template<typename C>
|
template<typename C>
|
||||||
void consume_while(C);
|
void consume_while(C);
|
||||||
|
|
||||||
template<typename C>
|
|
||||||
Vector<char, 128> extract_while(C);
|
|
||||||
|
|
||||||
StringView m_input;
|
StringView m_input;
|
||||||
int m_index { 0 };
|
int m_index { 0 };
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue