diff --git a/AK/ByteString.cpp b/AK/ByteString.cpp index 0ff35add19c..2f4d87ca32a 100644 --- a/AK/ByteString.cpp +++ b/AK/ByteString.cpp @@ -59,7 +59,7 @@ ByteString ByteString::isolated_copy() const char* buffer; auto impl = StringImpl::create_uninitialized(length(), buffer); memcpy(buffer, m_impl->characters(), m_impl->length()); - return ByteString(move(*impl)); + return impl; } ByteString ByteString::substring(size_t start, size_t length) const @@ -185,7 +185,7 @@ ByteString ByteString::repeated(char ch, size_t count) char* buffer; auto impl = StringImpl::create_uninitialized(count, buffer); memset(buffer, ch, count); - return *impl; + return impl; } ByteString ByteString::repeated(StringView string, size_t count) @@ -196,7 +196,7 @@ ByteString ByteString::repeated(StringView string, size_t count) auto impl = StringImpl::create_uninitialized(count * string.length(), buffer); for (size_t i = 0; i < count; i++) __builtin_memcpy(buffer + i * string.length(), string.characters_without_null_termination(), string.length()); - return *impl; + return impl; } ByteString ByteString::bijective_base_from(size_t value, unsigned base, StringView map) @@ -334,7 +334,7 @@ ByteString escape_html_entities(StringView html) } ByteString::ByteString(FlyString const& string) - : m_impl(*StringImpl::create(string.bytes())) + : m_impl(StringImpl::create(string.bytes())) { } @@ -349,7 +349,7 @@ ByteString ByteString::to_lowercase() const for (auto [i, character] : enumerate(view())) buffer[i] = static_cast(to_ascii_lowercase(character)); - return *impl; + return impl; } ByteString ByteString::to_uppercase() const @@ -363,7 +363,7 @@ ByteString ByteString::to_uppercase() const for (auto [i, character] : enumerate(view())) buffer[i] = static_cast(to_ascii_uppercase(character)); - return *impl; + return impl; } ByteString ByteString::to_snakecase() const @@ -410,7 +410,7 @@ ErrorOr ByteString::from_utf8(ReadonlyBytes bytes) { if (!Utf8View(bytes).validate()) return Error::from_string_literal("ByteString::from_utf8: Input was not valid UTF-8"); - return ByteString { *StringImpl::create(bytes) }; + return StringImpl::create(bytes); } } diff --git a/AK/ByteString.h b/AK/ByteString.h index c0b0607c617..e179dca909c 100644 --- a/AK/ByteString.h +++ b/AK/ByteString.h @@ -46,7 +46,7 @@ public: } ByteString(StringView view) - : m_impl(*StringImpl::create(view.characters_without_null_termination(), view.length())) + : m_impl(StringImpl::create(view.characters_without_null_termination(), view.length())) { } @@ -62,17 +62,17 @@ public: } ByteString(char const* cstring, ShouldChomp shouldChomp = NoChomp) - : m_impl(*StringImpl::create(cstring, shouldChomp)) + : m_impl(StringImpl::create(cstring, shouldChomp)) { } ByteString(char const* cstring, size_t length, ShouldChomp shouldChomp = NoChomp) - : m_impl(*StringImpl::create(cstring, length, shouldChomp)) + : m_impl(StringImpl::create(cstring, length, shouldChomp)) { } explicit ByteString(ReadonlyBytes bytes, ShouldChomp shouldChomp = NoChomp) - : m_impl(*StringImpl::create(bytes, shouldChomp)) + : m_impl(StringImpl::create(bytes, shouldChomp)) { } @@ -82,7 +82,7 @@ public: } ByteString(NonnullRefPtr&& impl) - : m_impl(*move(impl)) + : m_impl(move(impl)) { } @@ -264,7 +264,7 @@ public: template T> ByteString& operator=(T bytes) { - m_impl = *StringImpl::create(bytes); + m_impl = StringImpl::create(bytes); return *this; } diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp index b0809690ca5..146786e970b 100644 --- a/AK/StringImpl.cpp +++ b/AK/StringImpl.cpp @@ -40,7 +40,7 @@ NonnullRefPtr StringImpl::create_uninitialized(size_t length, return new_stringimpl; } -RefPtr StringImpl::create(char const* cstring, size_t length, ShouldChomp should_chomp) +NonnullRefPtr StringImpl::create(char const* cstring, size_t length, ShouldChomp should_chomp) { if (should_chomp) { while (length) { @@ -62,7 +62,7 @@ RefPtr StringImpl::create(char const* cstring, size_t length, return new_stringimpl; } -RefPtr StringImpl::create(char const* cstring, ShouldChomp shouldChomp) +NonnullRefPtr StringImpl::create(char const* cstring, ShouldChomp shouldChomp) { if (!cstring || !*cstring) return the_empty_stringimpl(); @@ -70,12 +70,12 @@ RefPtr StringImpl::create(char const* cstring, ShouldChomp sho return create(cstring, strlen(cstring), shouldChomp); } -RefPtr StringImpl::create(ReadonlyBytes bytes, ShouldChomp shouldChomp) +NonnullRefPtr StringImpl::create(ReadonlyBytes bytes, ShouldChomp shouldChomp) { return StringImpl::create(reinterpret_cast(bytes.data()), bytes.size(), shouldChomp); } -RefPtr StringImpl::create_lowercased(char const* cstring, size_t length) +NonnullRefPtr StringImpl::create_lowercased(char const* cstring, size_t length) { if (!length) return the_empty_stringimpl(); @@ -86,7 +86,7 @@ RefPtr StringImpl::create_lowercased(char const* cstring, size return impl; } -RefPtr StringImpl::create_uppercased(char const* cstring, size_t length) +NonnullRefPtr StringImpl::create_uppercased(char const* cstring, size_t length) { if (!length) return the_empty_stringimpl(); diff --git a/AK/StringImpl.h b/AK/StringImpl.h index c5f4e18c62c..a7ea6be8192 100644 --- a/AK/StringImpl.h +++ b/AK/StringImpl.h @@ -7,8 +7,8 @@ #pragma once #include +#include #include -#include #include #include #include @@ -25,11 +25,11 @@ size_t allocation_size_for_stringimpl(size_t length); class StringImpl : public RefCounted { public: static NonnullRefPtr create_uninitialized(size_t length, char*& buffer); - static RefPtr create(char const* cstring, ShouldChomp = NoChomp); - static RefPtr create(char const* cstring, size_t length, ShouldChomp = NoChomp); - static RefPtr create(ReadonlyBytes, ShouldChomp = NoChomp); - static RefPtr create_lowercased(char const* cstring, size_t length); - static RefPtr create_uppercased(char const* cstring, size_t length); + static NonnullRefPtr create(char const* cstring, ShouldChomp = NoChomp); + static NonnullRefPtr create(char const* cstring, size_t length, ShouldChomp = NoChomp); + static NonnullRefPtr create(ReadonlyBytes, ShouldChomp = NoChomp); + static NonnullRefPtr create_lowercased(char const* cstring, size_t length); + static NonnullRefPtr create_uppercased(char const* cstring, size_t length); void operator delete(void* ptr) {