mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
AK: Don't call memcpy() in ByteBuffer::append(u8)
We can emit way nicer code for the just-append-a-single-byte case.
This commit is contained in:
parent
34a4ce7955
commit
22f6f0fc9e
1 changed files with 8 additions and 3 deletions
|
@ -192,7 +192,7 @@ public:
|
||||||
return MUST(get_bytes_for_writing(length));
|
return MUST(get_bytes_for_writing(length));
|
||||||
}
|
}
|
||||||
|
|
||||||
void append(char byte)
|
void append(u8 byte)
|
||||||
{
|
{
|
||||||
MUST(try_append(byte));
|
MUST(try_append(byte));
|
||||||
}
|
}
|
||||||
|
@ -204,9 +204,14 @@ public:
|
||||||
|
|
||||||
void append(void const* data, size_t data_size) { append({ data, data_size }); }
|
void append(void const* data, size_t data_size) { append({ data, data_size }); }
|
||||||
|
|
||||||
ErrorOr<void> try_append(char byte)
|
ErrorOr<void> try_append(u8 byte)
|
||||||
{
|
{
|
||||||
return try_append(&byte, 1);
|
auto old_size = size();
|
||||||
|
auto new_size = old_size + 1;
|
||||||
|
VERIFY(new_size > old_size);
|
||||||
|
TRY(try_resize(new_size));
|
||||||
|
data()[old_size] = byte;
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> try_append(ReadonlyBytes bytes)
|
ErrorOr<void> try_append(ReadonlyBytes bytes)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue