From e08c55dd8dc06edfa15a6ceba55443982206821b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 19 Feb 2023 23:00:24 +0100 Subject: [PATCH] AK: Make String const-correct internally --- AK/String.cpp | 8 ++++---- AK/String.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AK/String.cpp b/AK/String.cpp index d1dc6d2e9c5..69e44d37021 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -63,7 +63,7 @@ public: } bool is_fly_string() const { return m_is_fly_string; } - void set_fly_string(bool is_fly_string) { m_is_fly_string = is_fly_string; } + void set_fly_string(bool is_fly_string) const { m_is_fly_string = is_fly_string; } private: explicit StringData(size_t byte_count); @@ -75,7 +75,7 @@ private: mutable unsigned m_hash { 0 }; mutable bool m_has_hash { false }; bool m_substring { false }; - bool m_is_fly_string { false }; + mutable bool m_is_fly_string { false }; alignas(SubstringData) u8 m_bytes_or_substring_data[0]; }; @@ -165,7 +165,7 @@ void StringData::compute_hash() const } -String::String(NonnullRefPtr data) +String::String(NonnullRefPtr data) : m_data(&data.leak_ref()) { } @@ -485,7 +485,7 @@ String String::fly_string_data_to_string(Badge, uintptr_t const& data return String { *reinterpret_cast(&data) }; auto const* string_data = reinterpret_cast(data); - return String { NonnullRefPtr(*string_data) }; + return String { NonnullRefPtr(*string_data) }; } StringView String::fly_string_data_to_string_view(Badge, uintptr_t const& data) diff --git a/AK/String.h b/AK/String.h index aa9f570f41b..187f84458e3 100644 --- a/AK/String.h +++ b/AK/String.h @@ -230,7 +230,7 @@ private: u8 storage[MAX_SHORT_STRING_BYTE_COUNT] = { 0 }; }; - explicit String(NonnullRefPtr); + explicit String(NonnullRefPtr); explicit constexpr String(ShortString short_string) : m_short_string(short_string) @@ -241,7 +241,7 @@ private: union { ShortString m_short_string; - Detail::StringData* m_data { nullptr }; + Detail::StringData const* m_data { nullptr }; }; };