From a8aadf73e98a6aca7a610744e4d9971739338d84 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 8 Jul 2019 13:08:21 +0200 Subject: [PATCH] AK: Add JsonObject::set(key, &&value) overload. This dodges a whole bunch of value copying in JsonParser. --- AK/JsonObject.h | 7 ++++++- AK/JsonParser.cpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AK/JsonObject.h b/AK/JsonObject.h index cb8a71a40f8..2796db1c532 100644 --- a/AK/JsonObject.h +++ b/AK/JsonObject.h @@ -22,9 +22,14 @@ public: return (*it).value; } + void set(const String& key, JsonValue&& value) + { + m_members.set(key, move(value)); + } + void set(const String& key, const JsonValue& value) { - m_members.set(key, value); + m_members.set(key, JsonValue(value)); } template diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp index 0dde664b5ba..fe20cab0879 100644 --- a/AK/JsonParser.cpp +++ b/AK/JsonParser.cpp @@ -108,7 +108,7 @@ JsonValue JsonParser::parse_object() consume_specific(':'); consume_whitespace(); auto value = parse(); - object.set(name, value); + object.set(name, move(value)); consume_whitespace(); if (peek() == '}') break;