AK: Remove the public ByteBuffer::trim method

This removes the public trim() method because it is no longer
necessary. Callers can instead use resize().
This commit is contained in:
Gunnar Beutner 2021-05-31 00:39:08 +02:00 committed by Ali Mohammad Pur
parent 5f18cf75c5
commit d8b5fa9dfe
Notes: sideshowbarker 2024-07-18 17:08:19 +09:00
3 changed files with 8 additions and 13 deletions

View file

@ -50,7 +50,7 @@ public:
{
if (this != &other) {
if (m_size > other.size())
internal_trim(other.size(), true);
trim(other.size(), true);
else
resize(other.size());
__builtin_memcpy(data(), other.data(), other.size());
@ -126,11 +126,6 @@ public:
[[nodiscard]] void* end_pointer() { return data() + m_size; }
[[nodiscard]] void const* end_pointer() const { return data() + m_size; }
void trim(size_t size)
{
internal_trim(size, false);
}
[[nodiscard]] ByteBuffer slice(size_t offset, size_t size) const
{
// I cannot hand you a slice I don't have
@ -151,7 +146,7 @@ public:
ALWAYS_INLINE void resize(size_t new_size)
{
if (new_size <= m_size) {
trim(new_size);
trim(new_size, false);
return;
}
ensure_capacity(new_size);
@ -217,7 +212,7 @@ private:
other.m_inline = true;
}
void internal_trim(size_t size, bool may_discard_existing_data)
void trim(size_t size, bool may_discard_existing_data)
{
VERIFY(size <= m_size);
if (!m_inline && size <= inline_capacity) {

View file

@ -61,7 +61,7 @@ ByteBuffer IODevice::read(size_t max_size)
int nread = ::read(m_fd, buffer_ptr, remaining_buffer_space);
if (nread < 0) {
if (taken_from_buffered) {
buffer.trim(taken_from_buffered);
buffer.resize(taken_from_buffered);
return buffer;
}
set_error(errno);
@ -70,12 +70,12 @@ ByteBuffer IODevice::read(size_t max_size)
if (nread == 0) {
set_eof(true);
if (taken_from_buffered) {
buffer.trim(taken_from_buffered);
buffer.resize(taken_from_buffered);
return buffer;
}
return {};
}
buffer.trim(taken_from_buffered + nread);
buffer.resize(taken_from_buffered + nread);
return buffer;
}
@ -195,7 +195,7 @@ String IODevice::read_line(size_t max_size)
Vector<u8> new_buffered_data;
new_buffered_data.append(m_buffered_data.data() + line_index, m_buffered_data.size() - line_index);
m_buffered_data = move(new_buffered_data);
line.trim(line_index);
line.resize(line_index);
return String::copy(line, Chomp);
}
}

View file

@ -72,7 +72,7 @@ ByteBuffer UDPServer::receive(size_t size, sockaddr_in& in)
return {};
}
buf.trim(rlen);
buf.resize(rlen);
return buf;
}