diff --git a/AK/AKString.h b/AK/AKString.h index e75172a870b..617bb6ab392 100644 --- a/AK/AKString.h +++ b/AK/AKString.h @@ -36,9 +36,12 @@ public: String() {} - String(StringView view) - : m_impl(StringImpl::create(view.characters(), view.length())) + String(const StringView& view) { + if (view.m_string) + *this = String(*view.m_string); + else + m_impl = StringImpl::create(view.characters(), view.length()); } String(const String& other) diff --git a/AK/StringView.cpp b/AK/StringView.cpp index c2f538be849..7e110c894ad 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -4,7 +4,8 @@ namespace AK { StringView::StringView(const AK::String& string) - : m_characters(string.characters()) + : m_string(&string) + , m_characters(string.characters()) , m_length(string.length()) { } diff --git a/AK/StringView.h b/AK/StringView.h index 4ef404c8e08..8e5b31127d6 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -44,6 +44,8 @@ public: bool operator==(const String&) const; private: + friend class String; + const AK::String* m_string { nullptr }; const char* m_characters { nullptr }; int m_length { 0 }; };