mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 19:27:36 +00:00
AK+Userland: Remove nullability feature for the ByteBuffer type
Nobody seems to use this particular feature, in fact there were some bugs which were uncovered by removing operator bool.
This commit is contained in:
parent
c4d0b0cd6b
commit
53d0150827
16 changed files with 12 additions and 36 deletions
|
@ -28,7 +28,6 @@ public:
|
|||
{
|
||||
grow(other.size());
|
||||
VERIFY(m_size == other.size());
|
||||
VERIFY(!m_is_null);
|
||||
__builtin_memcpy(data(), other.data(), other.size());
|
||||
}
|
||||
|
||||
|
@ -96,10 +95,6 @@ public:
|
|||
|
||||
bool operator!=(ByteBuffer const& other) const { return !(*this == other); }
|
||||
|
||||
operator bool() const { return !is_null(); }
|
||||
bool operator!() const { return is_null(); }
|
||||
[[nodiscard]] bool is_null() const { return m_is_null; }
|
||||
|
||||
[[nodiscard]] u8& operator[](size_t i)
|
||||
{
|
||||
VERIFY(i < m_size);
|
||||
|
@ -152,7 +147,6 @@ public:
|
|||
|
||||
void grow(size_t new_size)
|
||||
{
|
||||
m_is_null = false;
|
||||
if (new_size <= m_size)
|
||||
return;
|
||||
if (new_size <= capacity()) {
|
||||
|
@ -208,20 +202,17 @@ private:
|
|||
ByteBuffer(size_t size)
|
||||
{
|
||||
grow(size);
|
||||
VERIFY(!m_is_null);
|
||||
VERIFY(m_size == size);
|
||||
}
|
||||
|
||||
void move_from(ByteBuffer&& other)
|
||||
{
|
||||
m_is_null = other.m_is_null;
|
||||
m_size = other.m_size;
|
||||
if (other.m_size > inline_capacity) {
|
||||
m_outline_buffer = other.m_outline_buffer;
|
||||
m_outline_capacity = other.m_outline_capacity;
|
||||
} else
|
||||
__builtin_memcpy(m_inline_buffer, other.m_inline_buffer, other.m_size);
|
||||
other.m_is_null = true;
|
||||
other.m_size = 0;
|
||||
}
|
||||
|
||||
|
@ -242,7 +233,6 @@ private:
|
|||
size_t capacity() const { return is_inline() ? inline_capacity : m_outline_capacity; }
|
||||
|
||||
size_t m_size { 0 };
|
||||
bool m_is_null { true };
|
||||
union {
|
||||
u8 m_inline_buffer[inline_capacity];
|
||||
struct {
|
||||
|
|
|
@ -240,8 +240,6 @@ public:
|
|||
template<typename BufferType>
|
||||
[[nodiscard]] static String copy(const BufferType& buffer, ShouldChomp should_chomp = NoChomp)
|
||||
{
|
||||
if (buffer.is_null())
|
||||
return {};
|
||||
if (buffer.is_empty())
|
||||
return empty();
|
||||
return String((const char*)buffer.data(), buffer.size(), should_chomp);
|
||||
|
|
|
@ -150,8 +150,6 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
// NOTE: Vector::is_null() exists for the benefit of String::copy().
|
||||
bool is_null() const { return false; }
|
||||
bool is_empty() const { return size() == 0; }
|
||||
ALWAYS_INLINE size_t size() const { return m_size; }
|
||||
size_t capacity() const { return m_capacity; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue