diff --git a/crates/bevy_ecs/src/storage/blob_vec.rs b/crates/bevy_ecs/src/storage/blob_vec.rs index e0032cb646ccde..a67d1d40b80e40 100644 --- a/crates/bevy_ecs/src/storage/blob_vec.rs +++ b/crates/bevy_ecs/src/storage/blob_vec.rs @@ -230,7 +230,9 @@ impl BlobVec { /// The `value` must match the [`layout`](`BlobVec::layout`) of the elements in the [`BlobVec`]. #[inline] pub unsafe fn push(&mut self, value: OwningPtr<'_>) { - self.reserve_exact(1); + if self.len == self.capacity { + self.reserve_exact(self.capacity.max(1)); + } let index = self.len; self.len += 1; self.initialize_unchecked(index, value); @@ -519,7 +521,7 @@ mod tests { } assert_eq!(blob_vec.len(), 1_000); - assert_eq!(blob_vec.capacity(), 1_000); + assert_eq!(blob_vec.capacity(), 1_024); } #[derive(Debug, Eq, PartialEq, Clone)] @@ -579,19 +581,19 @@ mod tests { push(&mut blob_vec, foo3.clone()); assert_eq!(blob_vec.len(), 3); - assert_eq!(blob_vec.capacity(), 3); + assert_eq!(blob_vec.capacity(), 4); let last_index = blob_vec.len() - 1; let value = swap_remove::(&mut blob_vec, last_index); assert_eq!(foo3, value); assert_eq!(blob_vec.len(), 2); - assert_eq!(blob_vec.capacity(), 3); + assert_eq!(blob_vec.capacity(), 4); let value = swap_remove::(&mut blob_vec, 0); assert_eq!(foo1, value); assert_eq!(blob_vec.len(), 1); - assert_eq!(blob_vec.capacity(), 3); + assert_eq!(blob_vec.capacity(), 4); foo2.a = 8; assert_eq!(get_mut::(&mut blob_vec, 0), &foo2);