mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 17:47:44 +00:00
ByteBuffer: Remove pointer() in favor of data()
We had two ways to get the data inside a ByteBuffer. That was silly.
This commit is contained in:
parent
dd696e7c75
commit
8f45a259fc
30 changed files with 89 additions and 92 deletions
|
@ -43,8 +43,8 @@ public:
|
|||
bool is_empty() const { return !m_size; }
|
||||
int size() const { return m_size; }
|
||||
|
||||
u8* pointer() { return m_data; }
|
||||
const u8* pointer() const { return m_data; }
|
||||
u8* data() { return m_data; }
|
||||
const u8* data() const { return m_data; }
|
||||
|
||||
u8* offset_pointer(int offset) { return m_data + offset; }
|
||||
const u8* offset_pointer(int offset) const { return m_data + offset; }
|
||||
|
@ -130,11 +130,8 @@ public:
|
|||
bool is_empty() const { return !m_impl || m_impl->is_empty(); }
|
||||
int size() const { return m_impl ? m_impl->size() : 0; }
|
||||
|
||||
u8* data() { return pointer(); }
|
||||
const u8* data() const { return pointer(); }
|
||||
|
||||
u8* pointer() { return m_impl ? m_impl->pointer() : nullptr; }
|
||||
const u8* pointer() const { return m_impl ? m_impl->pointer() : nullptr; }
|
||||
u8* data() { return m_impl ? m_impl->data() : nullptr; }
|
||||
const u8* data() const { return m_impl ? m_impl->data() : nullptr; }
|
||||
|
||||
u8* offset_pointer(int offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
|
||||
const u8* offset_pointer(int offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
|
||||
|
@ -146,7 +143,7 @@ public:
|
|||
{
|
||||
if (!m_impl)
|
||||
return {};
|
||||
return copy(m_impl->pointer(), m_impl->size());
|
||||
return copy(m_impl->data(), m_impl->size());
|
||||
}
|
||||
|
||||
// NOTE: trim() does not reallocate.
|
||||
|
@ -190,7 +187,7 @@ public:
|
|||
{
|
||||
int old_size = size();
|
||||
grow(size() + data_size);
|
||||
memcpy(pointer() + old_size, data, data_size);
|
||||
memcpy(this->data() + old_size, data, data_size);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -249,7 +246,7 @@ inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_uninitialized(int si
|
|||
inline NonnullRefPtr<ByteBufferImpl> ByteBufferImpl::create_zeroed(int size)
|
||||
{
|
||||
auto buffer = ::adopt(*new ByteBufferImpl(size));
|
||||
memset(buffer->pointer(), 0, size);
|
||||
memset(buffer->data(), 0, size);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ public:
|
|||
bool is_valid() const { return m_map != (void*)-1; }
|
||||
void unmap();
|
||||
|
||||
void* pointer() { return m_map; }
|
||||
const void* pointer() const { return m_map; }
|
||||
void* data() { return m_map; }
|
||||
const void* data() const { return m_map; }
|
||||
size_t size() const { return m_size; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -21,7 +21,7 @@ void StringBuilder::append(const StringView& str)
|
|||
if (str.is_empty())
|
||||
return;
|
||||
will_append(str.length());
|
||||
memcpy(m_buffer.pointer() + m_length, str.characters_without_null_termination(), str.length());
|
||||
memcpy(m_buffer.data() + m_length, str.characters_without_null_termination(), str.length());
|
||||
m_length += str.length();
|
||||
}
|
||||
|
||||
|
@ -30,14 +30,14 @@ void StringBuilder::append(const char* characters, int length)
|
|||
if (!length)
|
||||
return;
|
||||
will_append(length);
|
||||
memcpy(m_buffer.pointer() + m_length, characters, length);
|
||||
memcpy(m_buffer.data() + m_length, characters, length);
|
||||
m_length += length;
|
||||
}
|
||||
|
||||
void StringBuilder::append(char ch)
|
||||
{
|
||||
will_append(1);
|
||||
m_buffer.pointer()[m_length] = ch;
|
||||
m_buffer.data()[m_length] = ch;
|
||||
m_length += 1;
|
||||
}
|
||||
|
||||
|
@ -67,14 +67,14 @@ ByteBuffer StringBuilder::to_byte_buffer()
|
|||
|
||||
String StringBuilder::to_string()
|
||||
{
|
||||
auto string = String((const char*)m_buffer.pointer(), m_length);
|
||||
auto string = String((const char*)m_buffer.data(), m_length);
|
||||
clear();
|
||||
return string;
|
||||
}
|
||||
|
||||
StringView StringBuilder::string_view() const
|
||||
{
|
||||
return StringView { (const char*)m_buffer.pointer(), m_length };
|
||||
return StringView { (const char*)m_buffer.data(), m_length };
|
||||
}
|
||||
|
||||
void StringBuilder::clear()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue