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:
Andreas Kling 2022-02-13 12:27:07 +01:00
parent 34a4ce7955
commit 22f6f0fc9e

View file

@ -192,7 +192,7 @@ public:
return MUST(get_bytes_for_writing(length));
}
void append(char byte)
void append(u8 byte)
{
MUST(try_append(byte));
}
@ -204,9 +204,14 @@ public:
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)