mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +00:00
AK: Remove the m_length member for StringBuilder
Instead we can just use ByteBuffer::size() which already keeps track of the buffer's size.
This commit is contained in:
parent
4c32a128ef
commit
de0aa44bb6
2 changed files with 5 additions and 9 deletions
|
@ -18,7 +18,7 @@ namespace AK {
|
||||||
|
|
||||||
inline void StringBuilder::will_append(size_t size)
|
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;
|
needed_capacity += size;
|
||||||
VERIFY(!needed_capacity.has_overflow());
|
VERIFY(!needed_capacity.has_overflow());
|
||||||
// Prefer to completely use the existing capacity first
|
// Prefer to completely use the existing capacity first
|
||||||
|
@ -41,7 +41,6 @@ void StringBuilder::append(const StringView& str)
|
||||||
return;
|
return;
|
||||||
will_append(str.length());
|
will_append(str.length());
|
||||||
m_buffer.append(str.characters_without_null_termination(), 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)
|
void StringBuilder::append(const char* characters, size_t length)
|
||||||
|
@ -53,7 +52,6 @@ void StringBuilder::append(char ch)
|
||||||
{
|
{
|
||||||
will_append(1);
|
will_append(1);
|
||||||
m_buffer.append(&ch, 1);
|
m_buffer.append(&ch, 1);
|
||||||
m_length += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringBuilder::appendvf(const char* fmt, va_list ap)
|
void StringBuilder::appendvf(const char* fmt, va_list ap)
|
||||||
|
@ -83,13 +81,12 @@ String StringBuilder::build() const
|
||||||
|
|
||||||
StringView StringBuilder::string_view() const
|
StringView StringBuilder::string_view() const
|
||||||
{
|
{
|
||||||
return StringView { data(), m_length };
|
return StringView { data(), m_buffer.size() };
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringBuilder::clear()
|
void StringBuilder::clear()
|
||||||
{
|
{
|
||||||
m_buffer.clear();
|
m_buffer.clear();
|
||||||
m_length = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringBuilder::append_code_point(u32 code_point)
|
void StringBuilder::append_code_point(u32 code_point)
|
||||||
|
|
|
@ -44,9 +44,9 @@ public:
|
||||||
[[nodiscard]] StringView string_view() const;
|
[[nodiscard]] StringView string_view() const;
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
[[nodiscard]] size_t length() const { return m_length; }
|
[[nodiscard]] size_t length() const { return m_buffer.size(); }
|
||||||
[[nodiscard]] bool is_empty() const { return m_length == 0; }
|
[[nodiscard]] bool is_empty() const { return m_buffer.is_empty(); }
|
||||||
void trim(size_t count) { m_length -= count; }
|
void trim(size_t count) { m_buffer.resize(m_buffer.size() - count); }
|
||||||
|
|
||||||
template<class SeparatorType, class CollectionType>
|
template<class SeparatorType, class CollectionType>
|
||||||
void join(const SeparatorType& separator, const CollectionType& collection)
|
void join(const SeparatorType& separator, const CollectionType& collection)
|
||||||
|
@ -68,7 +68,6 @@ private:
|
||||||
|
|
||||||
static constexpr size_t inline_capacity = 128;
|
static constexpr size_t inline_capacity = 128;
|
||||||
AK::Detail::ByteBuffer<inline_capacity> m_buffer;
|
AK::Detail::ByteBuffer<inline_capacity> m_buffer;
|
||||||
size_t m_length { 0 };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue