mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-07 00:19:27 +00:00
AK: Return const& from JsonObject::get()
This adds a static JsonValue* s_null_value, which allows JsonObject::get to return a reference instaed of copying the return value. Since JsonValue is only 16 bytes, this seems like a reasonable compromise.
This commit is contained in:
parent
e0ed160372
commit
66526cbbaf
|
@ -47,10 +47,16 @@ public:
|
|||
int size() const { return m_members.size(); }
|
||||
bool is_empty() const { return m_members.is_empty(); }
|
||||
|
||||
JsonValue get(String const& key) const
|
||||
JsonValue const& get(String const& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value ? *value : JsonValue(JsonValue::Type::Null);
|
||||
static JsonValue* s_null_value { nullptr };
|
||||
if (!value) {
|
||||
if (!s_null_value)
|
||||
s_null_value = new JsonValue;
|
||||
return *s_null_value;
|
||||
}
|
||||
return *value;
|
||||
}
|
||||
|
||||
JsonValue get_or(String const& key, JsonValue const& alternative) const
|
||||
|
|
Loading…
Reference in a new issue