1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:37:34 +00:00

JsonValue: No need to null-check StringImpls if type is Type::String.

If you try to create a JsonValue from a null String(), it will become a
null JsonValue anyway.
This commit is contained in:
Andreas Kling 2019-06-29 12:03:53 +02:00
parent 50677a58d4
commit 7f224ade60

View file

@ -31,8 +31,9 @@ void JsonValue::copy_from(const JsonValue& other)
m_type = other.m_type; m_type = other.m_type;
switch (m_type) { switch (m_type) {
case Type::String: case Type::String:
ASSERT(!m_value.as_string);
m_value.as_string = other.m_value.as_string; m_value.as_string = other.m_value.as_string;
AK::ref_if_not_null(m_value.as_string); m_value.as_string->ref();
break; break;
case Type::Object: case Type::Object:
m_value.as_object = new JsonObject(*other.m_value.as_object); m_value.as_object = new JsonObject(*other.m_value.as_object);
@ -105,7 +106,7 @@ JsonValue::JsonValue(const String& value)
} else { } else {
m_type = Type::String; m_type = Type::String;
m_value.as_string = const_cast<StringImpl*>(value.impl()); m_value.as_string = const_cast<StringImpl*>(value.impl());
AK::ref_if_not_null(m_value.as_string); m_value.as_string->ref();
} }
} }
@ -125,7 +126,7 @@ void JsonValue::clear()
{ {
switch (m_type) { switch (m_type) {
case Type::String: case Type::String:
AK::deref_if_not_null(m_value.as_string); m_value.as_string->deref();
break; break;
case Type::Object: case Type::Object:
delete m_value.as_object; delete m_value.as_object;