26 lastSize -= lastSize >> 7;
32 uint8_t* newEnd = end + LEN;
33 if (newEnd <= buf.
end()) [[likely]] {
34 memcpy(end, data, LEN);
37 insertGrow(data, LEN);
41template void OutputBuffer::insertN<1>(
const void* __restrict data);
42template void OutputBuffer::insertN<2>(
const void* __restrict data);
43template void OutputBuffer::insertN<4>(
const void* __restrict data);
44template void OutputBuffer::insertN<8>(
const void* __restrict data);
49 uint8_t* newEnd = end + len;
50 if (newEnd <= buf.
end()) [[likely]] {
51 memcpy(end, data, len);
54 insertGrow(data, len);
61 size_t size =
end - buf.data();
65 return std::move(buf);
68void OutputBuffer::grow(
size_t len)
70 size_t oldSize = end - buf.
data();
71 size_t newSize = std::max(oldSize + len, oldSize + oldSize / 2);
73 end = buf.
data() + oldSize;
76uint8_t* OutputBuffer::allocateGrow(
size_t len)
84void OutputBuffer::insertGrow(
const void* __restrict data,
size_t len)
86 uint8_t* pos = allocateGrow(len);
87 memcpy(pos, data, len);
This class manages the lifetime of a block of memory.
void resize(size_t size)
Grow or shrink the memory block.
const T * data() const
Returns pointer to the start of the memory buffer.
void insertN(const void *data, size_t len)
OutputBuffer()
Create an empty output buffer.
MemBuffer< uint8_t > release() &&
Release ownership of the buffer.
This file implemented 3 utility functions:
constexpr auto end(const zstring_view &x)