Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "cpp_toolbelt",
version = "2.1.3",
version = "2.1.4",
)

bazel_dep(name = "platforms", version = "1.0.0")
Expand Down
12 changes: 8 additions & 4 deletions toolbelt/payload_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,14 @@ inline void PayloadBuffer::VectorPush(PayloadBuffer **self, VectorHeader *hdr,
// the allocated block header (before the start of the memory)
uint32_t *block = (*self)->ToAddress<uint32_t>(hdr->data);
uint32_t current_size = DecodeSize(block);
if (current_size == total_size) {
// Need to double the size of the memory.
void *vecp = Realloc(self, block, 2 * hdr->num_elements * sizeof(T), true,
enable_small_block);
const uint32_t needed = (hdr->num_elements + 1) * sizeof(T);
if (needed > current_size) {
// Grow to fit the next element; at least double prior capacity.
const uint32_t min_capacity =
2u * static_cast<uint32_t>(sizeof(T));
const uint32_t new_size = std::max<uint32_t>(
needed, std::max<uint32_t>(current_size * 2, min_capacity));
void *vecp = Realloc(self, block, new_size, true, enable_small_block);
VectorHeader *new_hdr = (*self)->ToAddress<VectorHeader>(hdr_offset);
new_hdr->data = (*self)->ToOffset(vecp);
hdr = new_hdr;
Expand Down
Loading