Skip to content

Commit 458879e

Browse files
committed
Split the reserve function
1 parent 1bf53d8 commit 458879e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

crates/bevy_ecs/src/storage/blob_vec.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,18 @@ impl BlobVec {
119119
}
120120
}
121121

122+
/// Reserves the minimum capacity for at least `additional` more elements to be inserted in the given `BlobVec`.
123+
#[inline]
124+
pub fn reserve(&mut self, additional: usize) {
125+
if self.capacity - self.len < additional {
126+
self.do_reserve(additional);
127+
}
128+
}
129+
122130
/// Similar to `reserve_exact`. This method ensures that the capacity will grow at least `self.capacity()` if there is no
123131
/// enough space to hold `additional` more elements.
124-
pub fn reserve(&mut self, additional: usize) {
132+
#[cold]
133+
fn do_reserve(&mut self, additional: usize) {
125134
let available_space = self.capacity - self.len;
126135
if available_space < additional && self.item_layout.size() > 0 {
127136
let increment = self.capacity.max(additional - available_space);

0 commit comments

Comments
 (0)