AK: Make Deprecated{Fly,}String and StringImpl const-correct

This commit is contained in:
Andreas Kling 2023-02-19 22:59:26 +01:00
parent 4b3e229157
commit a56dfd5c77
Notes: sideshowbarker 2024-07-17 18:13:59 +09:00
5 changed files with 27 additions and 28 deletions

View file

@ -24,9 +24,9 @@ struct DeprecatedFlyStringImplTraits : public Traits<StringImpl*> {
}
};
static Singleton<HashTable<StringImpl*, DeprecatedFlyStringImplTraits>> s_table;
static Singleton<HashTable<StringImpl const*, DeprecatedFlyStringImplTraits>> s_table;
static HashTable<StringImpl*, DeprecatedFlyStringImplTraits>& fly_impls()
static HashTable<StringImpl const*, DeprecatedFlyStringImplTraits>& fly_impls()
{
return *s_table;
}

View file

@ -29,7 +29,7 @@ public:
{
}
static DeprecatedFlyString from_fly_impl(NonnullRefPtr<StringImpl> impl)
static DeprecatedFlyString from_fly_impl(NonnullRefPtr<StringImpl const> impl)
{
VERIFY(impl->is_fly());
DeprecatedFlyString string;
@ -91,7 +91,7 @@ public:
}
private:
RefPtr<StringImpl> m_impl;
RefPtr<StringImpl const> m_impl;
};
template<>

View file

@ -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<StringImpl>, with a bit of syntactic sugar.
// RefPtr<StringImpl const>, 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<DeprecatedString&>(other).m_impl)
: m_impl(other.m_impl)
{
}
@ -73,21 +73,21 @@ public:
}
DeprecatedString(StringImpl const& impl)
: m_impl(const_cast<StringImpl&>(impl))
: m_impl(impl)
{
}
DeprecatedString(StringImpl const* impl)
: m_impl(const_cast<StringImpl*>(impl))
: m_impl(impl)
{
}
DeprecatedString(RefPtr<StringImpl>&& impl)
DeprecatedString(RefPtr<StringImpl const>&& impl)
: m_impl(move(impl))
{
}
DeprecatedString(NonnullRefPtr<StringImpl>&& impl)
DeprecatedString(NonnullRefPtr<StringImpl const>&& 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<StringImpl> m_impl;
RefPtr<StringImpl const> m_impl;
};
template<>

View file

@ -34,7 +34,7 @@ StringImpl::~StringImpl()
DeprecatedFlyString::did_destroy_impl({}, *this);
}
NonnullRefPtr<StringImpl> StringImpl::create_uninitialized(size_t length, char*& buffer)
NonnullRefPtr<StringImpl const> StringImpl::create_uninitialized(size_t length, char*& buffer)
{
VERIFY(length);
void* slot = kmalloc(allocation_size_for_stringimpl(length));
@ -45,7 +45,7 @@ NonnullRefPtr<StringImpl> StringImpl::create_uninitialized(size_t length, char*&
return new_stringimpl;
}
RefPtr<StringImpl> StringImpl::create(char const* cstring, size_t length, ShouldChomp should_chomp)
RefPtr<StringImpl const> StringImpl::create(char const* cstring, size_t length, ShouldChomp should_chomp)
{
if (!cstring)
return nullptr;
@ -70,7 +70,7 @@ RefPtr<StringImpl> StringImpl::create(char const* cstring, size_t length, Should
return new_stringimpl;
}
RefPtr<StringImpl> StringImpl::create(char const* cstring, ShouldChomp shouldChomp)
RefPtr<StringImpl const> StringImpl::create(char const* cstring, ShouldChomp shouldChomp)
{
if (!cstring)
return nullptr;
@ -81,12 +81,12 @@ RefPtr<StringImpl> StringImpl::create(char const* cstring, ShouldChomp shouldCho
return create(cstring, strlen(cstring), shouldChomp);
}
RefPtr<StringImpl> StringImpl::create(ReadonlyBytes bytes, ShouldChomp shouldChomp)
RefPtr<StringImpl const> StringImpl::create(ReadonlyBytes bytes, ShouldChomp shouldChomp)
{
return StringImpl::create(reinterpret_cast<char const*>(bytes.data()), bytes.size(), shouldChomp);
}
RefPtr<StringImpl> StringImpl::create_lowercased(char const* cstring, size_t length)
RefPtr<StringImpl const> StringImpl::create_lowercased(char const* cstring, size_t length)
{
if (!cstring)
return nullptr;
@ -99,7 +99,7 @@ RefPtr<StringImpl> StringImpl::create_lowercased(char const* cstring, size_t len
return impl;
}
RefPtr<StringImpl> StringImpl::create_uppercased(char const* cstring, size_t length)
RefPtr<StringImpl const> StringImpl::create_uppercased(char const* cstring, size_t length)
{
if (!cstring)
return nullptr;
@ -112,7 +112,7 @@ RefPtr<StringImpl> StringImpl::create_uppercased(char const* cstring, size_t len
return impl;
}
NonnullRefPtr<StringImpl> StringImpl::to_lowercase() const
NonnullRefPtr<StringImpl const> 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> StringImpl::to_lowercase() const
return const_cast<StringImpl&>(*this);
}
NonnullRefPtr<StringImpl> StringImpl::to_uppercase() const
NonnullRefPtr<StringImpl const> StringImpl::to_uppercase() const
{
for (size_t i = 0; i < m_length; ++i) {
if (is_ascii_lower_alpha(characters()[i]))

View file

@ -24,15 +24,15 @@ size_t allocation_size_for_stringimpl(size_t length);
class StringImpl : public RefCounted<StringImpl> {
public:
static NonnullRefPtr<StringImpl> create_uninitialized(size_t length, char*& buffer);
static RefPtr<StringImpl> create(char const* cstring, ShouldChomp = NoChomp);
static RefPtr<StringImpl> create(char const* cstring, size_t length, ShouldChomp = NoChomp);
static RefPtr<StringImpl> create(ReadonlyBytes, ShouldChomp = NoChomp);
static RefPtr<StringImpl> create_lowercased(char const* cstring, size_t length);
static RefPtr<StringImpl> create_uppercased(char const* cstring, size_t length);
static NonnullRefPtr<StringImpl const> create_uninitialized(size_t length, char*& buffer);
static RefPtr<StringImpl const> create(char const* cstring, ShouldChomp = NoChomp);
static RefPtr<StringImpl const> create(char const* cstring, size_t length, ShouldChomp = NoChomp);
static RefPtr<StringImpl const> create(ReadonlyBytes, ShouldChomp = NoChomp);
static RefPtr<StringImpl const> create_lowercased(char const* cstring, size_t length);
static RefPtr<StringImpl const> create_uppercased(char const* cstring, size_t length);
NonnullRefPtr<StringImpl> to_lowercase() const;
NonnullRefPtr<StringImpl> to_uppercase() const;
NonnullRefPtr<StringImpl const> to_lowercase() const;
NonnullRefPtr<StringImpl const> to_uppercase() const;
void operator delete(void* ptr)
{