Przeglądaj źródła

AK: Add JsonObject::set(key, &&value) overload.

This dodges a whole bunch of value copying in JsonParser.
Andreas Kling 6 lat temu
rodzic
commit
a8aadf73e9
2 zmienionych plików z 7 dodań i 2 usunięć
  1. 6 1
      AK/JsonObject.h
  2. 1 1
      AK/JsonParser.cpp

+ 6 - 1
AK/JsonObject.h

@@ -22,9 +22,14 @@ public:
         return (*it).value;
         return (*it).value;
     }
     }
 
 
+    void set(const String& key, JsonValue&& value)
+    {
+        m_members.set(key, move(value));
+    }
+
     void set(const String& key, const JsonValue& value)
     void set(const String& key, const JsonValue& value)
     {
     {
-        m_members.set(key, value);
+        m_members.set(key, JsonValue(value));
     }
     }
 
 
     template<typename Callback>
     template<typename Callback>

+ 1 - 1
AK/JsonParser.cpp

@@ -108,7 +108,7 @@ JsonValue JsonParser::parse_object()
         consume_specific(':');
         consume_specific(':');
         consume_whitespace();
         consume_whitespace();
         auto value = parse();
         auto value = parse();
-        object.set(name, value);
+        object.set(name, move(value));
         consume_whitespace();
         consume_whitespace();
         if (peek() == '}')
         if (peek() == '}')
             break;
             break;