mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
Json: Add efficient copy and move constructors for Json{Array,Object}
This helps avoid copying JsonValues during parsing.
This commit is contained in:
parent
cce2ea9bb0
commit
82826104e0
2 changed files with 50 additions and 1 deletions
|
@ -10,6 +10,30 @@ public:
|
||||||
JsonArray() {}
|
JsonArray() {}
|
||||||
~JsonArray() {}
|
~JsonArray() {}
|
||||||
|
|
||||||
|
JsonArray(const JsonArray& other)
|
||||||
|
: m_values(other.m_values)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray(JsonArray&& other)
|
||||||
|
: m_values(move(other.m_values))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray& operator=(const JsonArray& other)
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
m_values = other.m_values;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray& operator=(JsonArray&& other)
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
m_values = move(other.m_values);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
int size() const { return m_values.size(); }
|
int size() const { return m_values.size(); }
|
||||||
bool is_empty() const { return m_values.is_empty(); }
|
bool is_empty() const { return m_values.is_empty(); }
|
||||||
|
|
||||||
|
@ -18,6 +42,7 @@ public:
|
||||||
|
|
||||||
void clear() { m_values.clear(); }
|
void clear() { m_values.clear(); }
|
||||||
void append(const JsonValue& value) { m_values.append(value); }
|
void append(const JsonValue& value) { m_values.append(value); }
|
||||||
|
void append(JsonValue&& value) { m_values.append(move(value)); }
|
||||||
|
|
||||||
String serialized() const;
|
String serialized() const;
|
||||||
void serialize(StringBuilder&) const;
|
void serialize(StringBuilder&) const;
|
||||||
|
|
|
@ -11,6 +11,30 @@ public:
|
||||||
JsonObject() { }
|
JsonObject() { }
|
||||||
~JsonObject() {}
|
~JsonObject() {}
|
||||||
|
|
||||||
|
JsonObject(const JsonObject& other)
|
||||||
|
: m_members(other.m_members)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject(JsonObject&& other)
|
||||||
|
: m_members(move(other.m_members))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject& operator=(const JsonObject& other)
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
m_members = other.m_members;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject& operator=(JsonObject&& other)
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
m_members = move(other.m_members);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
int size() const { return m_members.size(); }
|
int size() const { return m_members.size(); }
|
||||||
bool is_empty() const { return m_members.is_empty(); }
|
bool is_empty() const { return m_members.is_empty(); }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue