diff options
Diffstat (limited to 'AK')
-rw-r--r-- | AK/StringBuilder.cpp | 7 | ||||
-rw-r--r-- | AK/StringBuilder.h | 7 |
2 files changed, 5 insertions, 9 deletions
diff --git a/AK/StringBuilder.cpp b/AK/StringBuilder.cpp index 0a363a5355..7a76fcae33 100644 --- a/AK/StringBuilder.cpp +++ b/AK/StringBuilder.cpp @@ -18,7 +18,7 @@ namespace AK { inline void StringBuilder::will_append(size_t size) { - Checked<size_t> needed_capacity = m_length; + Checked<size_t> needed_capacity = m_buffer.size(); needed_capacity += size; VERIFY(!needed_capacity.has_overflow()); // Prefer to completely use the existing capacity first @@ -41,7 +41,6 @@ void StringBuilder::append(const StringView& str) return; will_append(str.length()); m_buffer.append(str.characters_without_null_termination(), str.length()); - m_length += str.length(); } void StringBuilder::append(const char* characters, size_t length) @@ -53,7 +52,6 @@ void StringBuilder::append(char ch) { will_append(1); m_buffer.append(&ch, 1); - m_length += 1; } void StringBuilder::appendvf(const char* fmt, va_list ap) @@ -83,13 +81,12 @@ String StringBuilder::build() const StringView StringBuilder::string_view() const { - return StringView { data(), m_length }; + return StringView { data(), m_buffer.size() }; } void StringBuilder::clear() { m_buffer.clear(); - m_length = 0; } void StringBuilder::append_code_point(u32 code_point) diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h index bc0470a211..118e5c0958 100644 --- a/AK/StringBuilder.h +++ b/AK/StringBuilder.h @@ -44,9 +44,9 @@ public: [[nodiscard]] StringView string_view() const; void clear(); - [[nodiscard]] size_t length() const { return m_length; } - [[nodiscard]] bool is_empty() const { return m_length == 0; } - void trim(size_t count) { m_length -= count; } + [[nodiscard]] size_t length() const { return m_buffer.size(); } + [[nodiscard]] bool is_empty() const { return m_buffer.is_empty(); } + void trim(size_t count) { m_buffer.resize(m_buffer.size() - count); } template<class SeparatorType, class CollectionType> void join(const SeparatorType& separator, const CollectionType& collection) @@ -68,7 +68,6 @@ private: static constexpr size_t inline_capacity = 128; AK::Detail::ByteBuffer<inline_capacity> m_buffer; - size_t m_length { 0 }; }; } |