mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-22 02:26:11 +00:00
AK: Add JsonObject::get_ptr() for copy-free lookup
This variant of get() returns a const JsonValue* instead of a JsonValue and can be used when you want to peek into a JsonObject's member fields without making copies.
This commit is contained in:
parent
b0bbdc53e9
commit
7011dba98e
|
@ -41,11 +41,17 @@ public:
|
|||
bool is_empty() const { return m_members.is_empty(); }
|
||||
|
||||
JsonValue get(const String& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value ? *value : JsonValue(JsonValue::Type::Undefined);
|
||||
}
|
||||
|
||||
const JsonValue* get_ptr(const String& key) const
|
||||
{
|
||||
auto it = m_members.find(key);
|
||||
if (it == m_members.end())
|
||||
return JsonValue(JsonValue::Type::Undefined);
|
||||
return (*it).value;
|
||||
return nullptr;
|
||||
return &(*it).value;
|
||||
}
|
||||
|
||||
bool has(const String& key) const
|
||||
|
|
Loading…
Reference in a new issue