From a56dfd5c77616dee640bce93f7014309ea946867 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 19 Feb 2023 22:59:26 +0100 Subject: [PATCH] AK: Make Deprecated{Fly,}String and StringImpl const-correct --- AK/DeprecatedFlyString.cpp | 4 ++-- AK/DeprecatedFlyString.h | 4 ++-- AK/DeprecatedString.h | 15 +++++++-------- AK/StringImpl.cpp | 16 ++++++++-------- AK/StringImpl.h | 16 ++++++++-------- 5 files changed, 27 insertions(+), 28 deletions(-) diff --git a/AK/DeprecatedFlyString.cpp b/AK/DeprecatedFlyString.cpp index 1d437702896..84e6fc9c7a7 100644 --- a/AK/DeprecatedFlyString.cpp +++ b/AK/DeprecatedFlyString.cpp @@ -24,9 +24,9 @@ struct DeprecatedFlyStringImplTraits : public Traits { } }; -static Singleton> s_table; +static Singleton> s_table; -static HashTable& fly_impls() +static HashTable& fly_impls() { return *s_table; } diff --git a/AK/DeprecatedFlyString.h b/AK/DeprecatedFlyString.h index 513cbc3134d..395cb1496e5 100644 --- a/AK/DeprecatedFlyString.h +++ b/AK/DeprecatedFlyString.h @@ -29,7 +29,7 @@ public: { } - static DeprecatedFlyString from_fly_impl(NonnullRefPtr impl) + static DeprecatedFlyString from_fly_impl(NonnullRefPtr impl) { VERIFY(impl->is_fly()); DeprecatedFlyString string; @@ -91,7 +91,7 @@ public: } private: - RefPtr m_impl; + RefPtr m_impl; }; template<> diff --git a/AK/DeprecatedString.h b/AK/DeprecatedString.h index fd89efcb3ac..98e264385e1 100644 --- a/AK/DeprecatedString.h +++ b/AK/DeprecatedString.h @@ -18,7 +18,7 @@ namespace AK { // DeprecatedString is a convenience wrapper around StringImpl, suitable for passing // around as a value type. It's basically the same as passing around a -// RefPtr, with a bit of syntactic sugar. +// RefPtr, with a bit of syntactic sugar. // // Note that StringImpl is an immutable object that cannot shrink or grow. // Its allocation size is snugly tailored to the specific string it contains. @@ -48,7 +48,7 @@ public: } DeprecatedString(DeprecatedString const& other) - : m_impl(const_cast(other).m_impl) + : m_impl(other.m_impl) { } @@ -73,21 +73,21 @@ public: } DeprecatedString(StringImpl const& impl) - : m_impl(const_cast(impl)) + : m_impl(impl) { } DeprecatedString(StringImpl const* impl) - : m_impl(const_cast(impl)) + : m_impl(impl) { } - DeprecatedString(RefPtr&& impl) + DeprecatedString(RefPtr&& impl) : m_impl(move(impl)) { } - DeprecatedString(NonnullRefPtr&& impl) + DeprecatedString(NonnullRefPtr&& impl) : m_impl(move(impl)) { } @@ -234,7 +234,6 @@ public: return StringImpl::the_empty_stringimpl(); } - [[nodiscard]] StringImpl* impl() { return m_impl.ptr(); } [[nodiscard]] StringImpl const* impl() const { return m_impl.ptr(); } DeprecatedString& operator=(DeprecatedString&& other) @@ -323,7 +322,7 @@ public: } private: - RefPtr m_impl; + RefPtr m_impl; }; template<> diff --git a/AK/StringImpl.cpp b/AK/StringImpl.cpp index 414383502bf..1c7d8b6d070 100644 --- a/AK/StringImpl.cpp +++ b/AK/StringImpl.cpp @@ -34,7 +34,7 @@ StringImpl::~StringImpl() DeprecatedFlyString::did_destroy_impl({}, *this); } -NonnullRefPtr StringImpl::create_uninitialized(size_t length, char*& buffer) +NonnullRefPtr StringImpl::create_uninitialized(size_t length, char*& buffer) { VERIFY(length); void* slot = kmalloc(allocation_size_for_stringimpl(length)); @@ -45,7 +45,7 @@ NonnullRefPtr StringImpl::create_uninitialized(size_t length, char*& return new_stringimpl; } -RefPtr StringImpl::create(char const* cstring, size_t length, ShouldChomp should_chomp) +RefPtr StringImpl::create(char const* cstring, size_t length, ShouldChomp should_chomp) { if (!cstring) return nullptr; @@ -70,7 +70,7 @@ RefPtr StringImpl::create(char const* cstring, size_t length, Should return new_stringimpl; } -RefPtr StringImpl::create(char const* cstring, ShouldChomp shouldChomp) +RefPtr StringImpl::create(char const* cstring, ShouldChomp shouldChomp) { if (!cstring) return nullptr; @@ -81,12 +81,12 @@ RefPtr StringImpl::create(char const* cstring, ShouldChomp shouldCho return create(cstring, strlen(cstring), shouldChomp); } -RefPtr StringImpl::create(ReadonlyBytes bytes, ShouldChomp shouldChomp) +RefPtr 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) +RefPtr StringImpl::create_lowercased(char const* cstring, size_t length) { if (!cstring) return nullptr; @@ -99,7 +99,7 @@ RefPtr StringImpl::create_lowercased(char const* cstring, size_t len return impl; } -RefPtr StringImpl::create_uppercased(char const* cstring, size_t length) +RefPtr StringImpl::create_uppercased(char const* cstring, size_t length) { if (!cstring) return nullptr; @@ -112,7 +112,7 @@ RefPtr StringImpl::create_uppercased(char const* cstring, size_t len return impl; } -NonnullRefPtr StringImpl::to_lowercase() const +NonnullRefPtr StringImpl::to_lowercase() const { for (size_t i = 0; i < m_length; ++i) { if (is_ascii_upper_alpha(characters()[i])) @@ -121,7 +121,7 @@ NonnullRefPtr StringImpl::to_lowercase() const return const_cast(*this); } -NonnullRefPtr StringImpl::to_uppercase() const +NonnullRefPtr StringImpl::to_uppercase() const { for (size_t i = 0; i < m_length; ++i) { if (is_ascii_lower_alpha(characters()[i])) diff --git a/AK/StringImpl.h b/AK/StringImpl.h index 00b40812b53..435b5815aca 100644 --- a/AK/StringImpl.h +++ b/AK/StringImpl.h @@ -24,15 +24,15 @@ 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_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); - NonnullRefPtr to_lowercase() const; - NonnullRefPtr to_uppercase() const; + NonnullRefPtr to_lowercase() const; + NonnullRefPtr to_uppercase() const; void operator delete(void* ptr) {