Skip to content

Commit f4c91d7

Browse files
committed
Fix the capacity of poolable for Vec<T>
A vector can allocate more space than the current number of elements, this allows it to cheaply grow the elements. This is what vec.capacity() returns. vec.len() returns the actual number of items in use, this is also the number of items you will get when slicing with e.g. vec[..]. This latter matters since this is how the block is meant to be used: a lot of consumers silce the block. Hence vec.len() gives the actual capacity of the block. This is also reflected with how the block (re)allocates capacity: vec.resize() changes the Vec's len with no guarantees how it affects the Vec capacity.
1 parent b96f83c commit f4c91d7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/poolable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub trait Poolable {
99

1010
impl<T: Default + Clone> Poolable for Vec<T> {
1111
fn capacity(&self) -> usize {
12-
self.capacity()
12+
self.len()
1313
}
1414

1515
fn alloc(size: usize) -> Self {

0 commit comments

Comments
 (0)