Skip to content

Commit

Permalink
Add capacity api for CollisionObjectSlab
Browse files Browse the repository at this point in the history
  • Loading branch information
FenQiDian committed Aug 15, 2020
1 parent edefbbb commit 2654cc9
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/pipeline/object/collision_object_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ impl<N: RealField, T> CollisionObjectSlab<N, T> {
objects: Slab::new(),
}
}

/// Constructs a new empty collection with the specified capacity.
pub fn with_capacity(capacity: usize) -> CollisionObjectSlab<N, T> {
CollisionObjectSlab {
objects: Slab::with_capacity(capacity),
}
}

/// Inserts a new collision object into this collection and returns the corresponding handle.
#[inline]
Expand Down Expand Up @@ -136,6 +143,26 @@ impl<N: RealField, T> CollisionObjectSlab<N, T> {
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<N: RealField, T> Index<CollisionObjectSlabHandle> for CollisionObjectSlab<N, T> {
Expand Down

0 comments on commit 2654cc9

Please sign in to comment.