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:
Andreas Kling 2021-05-14 11:54:43 +02:00
parent 6210d2612e
commit fccfc33dfb
Notes: sideshowbarker 2024-07-18 18:10:26 +09:00

View File

@ -98,7 +98,7 @@ Optional<JsonValue> JsonParser::parse_object()
auto value = parse_helper();
if (!value.has_value())
return {};
object.set(name, move(value.value()));
object.set(name, value.release_value());
ignore_while(isspace);
if (peek() == '}')
break;
@ -110,7 +110,7 @@ Optional<JsonValue> JsonParser::parse_object()
}
if (!consume_specific('}'))
return {};
return object;
return JsonValue { move(object) };
}
Optional<JsonValue> JsonParser::parse_array()
@ -125,7 +125,7 @@ Optional<JsonValue> JsonParser::parse_array()
auto element = parse_helper();
if (!element.has_value())
return {};
array.append(element.value());
array.append(element.release_value());
ignore_while(isspace);
if (peek() == ']')
break;
@ -138,7 +138,7 @@ Optional<JsonValue> JsonParser::parse_array()
ignore_while(isspace);
if (!consume_specific(']'))
return {};
return array;
return JsonValue { move(array) };
}
Optional<JsonValue> JsonParser::parse_string()