mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 14:14:45 +03: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
Notes:
sideshowbarker
2024-07-18 18:10:26 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/fccfc33dfbc
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user