mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:08:10 +00:00
AK: Use move semantics to avoid copying in JSON parser
The JSON parser was deep-copying JsonValues left and right, and it was all totally avoidable. :^)
This commit is contained in:
parent
6210d2612e
commit
fccfc33dfb
1 changed files with 4 additions and 4 deletions
|
@ -98,7 +98,7 @@ Optional<JsonValue> JsonParser::parse_object()
|
||||||
auto value = parse_helper();
|
auto value = parse_helper();
|
||||||
if (!value.has_value())
|
if (!value.has_value())
|
||||||
return {};
|
return {};
|
||||||
object.set(name, move(value.value()));
|
object.set(name, value.release_value());
|
||||||
ignore_while(isspace);
|
ignore_while(isspace);
|
||||||
if (peek() == '}')
|
if (peek() == '}')
|
||||||
break;
|
break;
|
||||||
|
@ -110,7 +110,7 @@ Optional<JsonValue> JsonParser::parse_object()
|
||||||
}
|
}
|
||||||
if (!consume_specific('}'))
|
if (!consume_specific('}'))
|
||||||
return {};
|
return {};
|
||||||
return object;
|
return JsonValue { move(object) };
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<JsonValue> JsonParser::parse_array()
|
Optional<JsonValue> JsonParser::parse_array()
|
||||||
|
@ -125,7 +125,7 @@ Optional<JsonValue> JsonParser::parse_array()
|
||||||
auto element = parse_helper();
|
auto element = parse_helper();
|
||||||
if (!element.has_value())
|
if (!element.has_value())
|
||||||
return {};
|
return {};
|
||||||
array.append(element.value());
|
array.append(element.release_value());
|
||||||
ignore_while(isspace);
|
ignore_while(isspace);
|
||||||
if (peek() == ']')
|
if (peek() == ']')
|
||||||
break;
|
break;
|
||||||
|
@ -138,7 +138,7 @@ Optional<JsonValue> JsonParser::parse_array()
|
||||||
ignore_while(isspace);
|
ignore_while(isspace);
|
||||||
if (!consume_specific(']'))
|
if (!consume_specific(']'))
|
||||||
return {};
|
return {};
|
||||||
return array;
|
return JsonValue { move(array) };
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<JsonValue> JsonParser::parse_string()
|
Optional<JsonValue> JsonParser::parse_string()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue