diff --git a/src/pipeline/object/collision_object_set.rs b/src/pipeline/object/collision_object_set.rs index 563b95bfa..4a54633b6 100644 --- a/src/pipeline/object/collision_object_set.rs +++ b/src/pipeline/object/collision_object_set.rs @@ -60,6 +60,13 @@ impl CollisionObjectSlab { } } + /// Constructs a new empty collection with the specified capacity. + pub fn with_capacity(capacity: usize) -> CollisionObjectSlab { + CollisionObjectSlab { + objects: Slab::with_capacity(capacity), + } + } + /// Inserts a new collision object into this collection and returns the corresponding handle. #[inline] pub fn insert(&mut self, co: CollisionObject) -> CollisionObjectSlabHandle { @@ -136,6 +143,26 @@ impl CollisionObjectSlab { pub fn len(&self) -> usize { self.objects.len() } + + /// Return the number of values the slab can store without reallocating. + #[inline] + pub fn capacity(&self) -> usize { + self.objects.capacity() + } + + /// Reserve capacity for at least `additional` more values to be stored + /// without allocating. + #[inline] + pub fn reserve(&mut self, additional: usize) { + self.objects.reserve(additional); + } + + /// Reserve the minimum capacity required to store exactly `additional` + /// more values. + #[inline] + pub fn reserve_exact(&mut self, additional: usize) { + self.objects.reserve_exact(additional); + } } impl Index for CollisionObjectSlab {