diff --git a/AK/ByteString.cpp b/AK/ByteString.cpp index 1efd396105..9ac308511f 100644 --- a/AK/ByteString.cpp +++ b/AK/ByteString.cpp @@ -338,7 +338,7 @@ ByteString escape_html_entities(StringView html) } ByteString::ByteString(DeprecatedFlyString const& string) - : m_impl(*(string.impl() ?: &StringImpl::the_empty_stringimpl())) + : m_impl(string.impl()) { } diff --git a/AK/ByteString.h b/AK/ByteString.h index 052e0571f8..f4f5023d5c 100644 --- a/AK/ByteString.h +++ b/AK/ByteString.h @@ -239,7 +239,7 @@ public: return StringImpl::the_empty_stringimpl(); } - [[nodiscard]] StringImpl const* impl() const { return m_impl.ptr(); } + [[nodiscard]] NonnullRefPtr impl() const { return m_impl; } ByteString& operator=(ByteString&& other) { @@ -325,12 +325,12 @@ private: template<> struct Traits : public DefaultTraits { - static unsigned hash(ByteString const& s) { return s.impl() ? s.impl()->hash() : 0; } + static unsigned hash(ByteString const& s) { return s.impl()->hash(); } }; // FIXME: Rename this to indicate that it's about ASCII-only case insensitivity. struct CaseInsensitiveStringTraits : public Traits { - static unsigned hash(ByteString const& s) { return s.impl() ? s.impl()->case_insensitive_hash() : 0; } + static unsigned hash(ByteString const& s) { return s.impl()->case_insensitive_hash(); } static bool equals(ByteString const& a, ByteString const& b) { return a.equals_ignoring_ascii_case(b); } }; diff --git a/AK/DeprecatedFlyString.cpp b/AK/DeprecatedFlyString.cpp index e5d77f6f1a..252fc3c8b2 100644 --- a/AK/DeprecatedFlyString.cpp +++ b/AK/DeprecatedFlyString.cpp @@ -14,12 +14,10 @@ namespace AK { -struct DeprecatedFlyStringImplTraits : public Traits { - static unsigned hash(StringImpl const* s) { return s ? s->hash() : 0; } +struct DeprecatedFlyStringImplTraits : public Traits { + static unsigned hash(StringImpl const* s) { return s->hash(); } static bool equals(StringImpl const* a, StringImpl const* b) { - VERIFY(a); - VERIFY(b); return *a == *b; } }; @@ -37,23 +35,24 @@ void DeprecatedFlyString::did_destroy_impl(Badge, StringImpl& impl) } DeprecatedFlyString::DeprecatedFlyString(ByteString const& string) + : m_impl(string.impl()) { - if (string.impl()->is_fly()) { - m_impl = string.impl(); + if (string.impl()->is_fly()) return; - } - auto it = fly_impls().find(const_cast(string.impl())); + + auto it = fly_impls().find(string.impl()); if (it == fly_impls().end()) { - fly_impls().set(const_cast(string.impl())); + fly_impls().set(string.impl()); string.impl()->set_fly({}, true); m_impl = string.impl(); } else { VERIFY((*it)->is_fly()); - m_impl = *it; + m_impl = **it; } } DeprecatedFlyString::DeprecatedFlyString(StringView string) + : m_impl(StringImpl::the_empty_stringimpl()) { if (string.is_null()) return; @@ -67,7 +66,7 @@ DeprecatedFlyString::DeprecatedFlyString(StringView string) m_impl = new_string.impl(); } else { VERIFY((*it)->is_fly()); - m_impl = *it; + m_impl = **it; } } diff --git a/AK/DeprecatedFlyString.h b/AK/DeprecatedFlyString.h index 51aa425c96..d952f5e1be 100644 --- a/AK/DeprecatedFlyString.h +++ b/AK/DeprecatedFlyString.h @@ -13,7 +13,10 @@ namespace AK { class DeprecatedFlyString { public: - DeprecatedFlyString() = default; + DeprecatedFlyString() + : m_impl(StringImpl::the_empty_stringimpl()) + { + } DeprecatedFlyString(DeprecatedFlyString const& other) : m_impl(other.impl()) { @@ -49,8 +52,7 @@ public: return *this; } - bool is_empty() const { return !m_impl || !m_impl->length(); } - bool is_null() const { return !m_impl; } + bool is_empty() const { return !m_impl->length(); } bool operator==(DeprecatedFlyString const& other) const { return m_impl == other.m_impl; } @@ -60,12 +62,12 @@ public: bool operator==(char const*) const; - StringImpl const* impl() const { return m_impl; } - char const* characters() const { return m_impl ? m_impl->characters() : nullptr; } - size_t length() const { return m_impl ? m_impl->length() : 0; } + NonnullRefPtr impl() const { return m_impl; } + char const* characters() const { return m_impl->characters(); } + size_t length() const { return m_impl->length(); } - ALWAYS_INLINE u32 hash() const { return m_impl ? m_impl->existing_hash() : 0; } - ALWAYS_INLINE StringView view() const { return m_impl ? m_impl->view() : StringView {}; } + ALWAYS_INLINE u32 hash() const { return m_impl->existing_hash(); } + ALWAYS_INLINE StringView view() const { return m_impl->view(); } DeprecatedFlyString to_lowercase() const; @@ -88,7 +90,7 @@ public: } private: - RefPtr m_impl; + NonnullRefPtr m_impl; }; template<> diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index bb8c642372..79444dcdf5 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -1261,7 +1261,6 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body() void ECMAScriptFunctionObject::set_name(DeprecatedFlyString const& name) { - VERIFY(!name.is_null()); auto& vm = this->vm(); m_name = name; m_name_string = PrimitiveString::create(vm, m_name); diff --git a/Userland/Libraries/LibJS/Runtime/PropertyKey.h b/Userland/Libraries/LibJS/Runtime/PropertyKey.h index d10a694d99..24319b6558 100644 --- a/Userland/Libraries/LibJS/Runtime/PropertyKey.h +++ b/Userland/Libraries/LibJS/Runtime/PropertyKey.h @@ -69,7 +69,6 @@ public: : m_type(Type::String) , m_string(DeprecatedFlyString(string)) { - VERIFY(!m_string.is_null()); } PropertyKey(DeprecatedFlyString string, StringMayBeNumber string_may_be_number = StringMayBeNumber::Yes) @@ -77,7 +76,6 @@ public: , m_type(Type::String) , m_string(move(string)) { - VERIFY(!m_string.is_null()); } PropertyKey(NonnullGCPtr symbol) diff --git a/Userland/Libraries/LibJS/Runtime/StringOrSymbol.h b/Userland/Libraries/LibJS/Runtime/StringOrSymbol.h index 728eb7ded0..473ed3e7f5 100644 --- a/Userland/Libraries/LibJS/Runtime/StringOrSymbol.h +++ b/Userland/Libraries/LibJS/Runtime/StringOrSymbol.h @@ -33,7 +33,6 @@ public: StringOrSymbol(DeprecatedFlyString const& string) : m_string(string) { - VERIFY(!string.is_null()); } ~StringOrSymbol()