mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:57:35 +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
1 changed files with 8 additions and 2 deletions
|
@ -41,11 +41,17 @@ public:
|
||||||
bool is_empty() const { return m_members.is_empty(); }
|
bool is_empty() const { return m_members.is_empty(); }
|
||||||
|
|
||||||
JsonValue get(const String& key) const
|
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);
|
auto it = m_members.find(key);
|
||||||
if (it == m_members.end())
|
if (it == m_members.end())
|
||||||
return JsonValue(JsonValue::Type::Undefined);
|
return nullptr;
|
||||||
return (*it).value;
|
return &(*it).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has(const String& key) const
|
bool has(const String& key) const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue