summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-31 00:58:07 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-05-31 14:49:00 +0430
commitde0aa44bb66241be8a71843471fef12dac9e9673 (patch)
treeb4e4709b31a903919feb29888e583ae0c8ffff84
parent4c32a128ef640e6cd6030fc7f51dafde3c3d1078 (diff)
downloadserenity-de0aa44bb66241be8a71843471fef12dac9e9673.zip
AK: Remove the m_length member for StringBuilder
Instead we can just use ByteBuffer::size() which already keeps track of the buffer's size.
-rw-r--r--AK/StringBuilder.cpp7
-rw-r--r--AK/StringBuilder.h7
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 };
};
}