Skip to content

Commit 8cfa559

Browse files
committed
Fix allocation behavior
Signed-off-by: Moritz Hoffmann <[email protected]>
1 parent 5f7ff7c commit 8cfa559

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/ore/src/flatcontainer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ mod lgalloc {
483483
#[inline]
484484
fn clear(&mut self) {
485485
self.slices.clear();
486+
self.offsets.clear();
487+
self.offsets.push(0);
486488
}
487489

488490
#[inline]

src/ore/src/region.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -554,14 +554,18 @@ mod vec {
554554
}
555555
}
556556

557+
const MIN_NON_ZERO_CAP: usize = if std::mem::size_of::<T>() == 1 {
558+
8
559+
} else if std::mem::size_of::<T>() <= 1024 {
560+
4
561+
} else {
562+
1
563+
};
564+
557565
/// Grow the array to at least `new_len` elements. Reallocates the underlying storage.
558566
fn grow(&mut self, new_len: usize) {
559567
let new_capacity = std::cmp::max(self.capacity() * 2, new_len);
560-
println!(
561-
"Reallocating {} -> {}, requested {new_len}",
562-
self.capacity(),
563-
new_capacity
564-
);
568+
let new_capacity = std::cmp::max(new_capacity, Self::MIN_NON_ZERO_CAP);
565569
let mut new_vec = LgAllocVec::with_capacity(new_capacity);
566570

567571
let src_ptr = self.elements.as_ptr();

0 commit comments

Comments
 (0)