mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +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
Notes:
sideshowbarker
2024-07-18 11:21:28 +09:00
Author: https://github.com/MaxWipfli Commit: https://github.com/SerenityOS/serenity/commit/66526cbbaf4 Pull-request: https://github.com/SerenityOS/serenity/pull/8293 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling
1 changed files with 8 additions and 2 deletions
|
@ -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…
Add table
Reference in a new issue