Lines Matching full:capacity

38 /// * Catches all overflows in capacity computations (promotes them to "capacity overflow" panics).
43 /// * Uses the excess returned from the allocator to use the largest available capacity.
49 /// Note that the excess of a zero-sized types is always infinite, so `capacity()` always returns
51 /// `Box<[T]>`, since `capacity()` won't yield the length.
69 /// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a
70 /// `RawVec` with capacity `usize::MAX`. Useful for implementing
78 /// capacity and alignment requirements for a `[T; capacity]`. This is
79 /// equivalent to calling `RawVec::new` when `capacity` is `0` or `T` is
81 /// *not* get a `RawVec` with the requested capacity.
85 /// Panics if the requested capacity exceeds `isize::MAX` bytes.
93 pub fn with_capacity(capacity: usize) -> Self { in with_capacity()
94 Self::with_capacity_in(capacity, Global) in with_capacity()
101 pub fn with_capacity_zeroed(capacity: usize) -> Self { in with_capacity_zeroed()
102 Self::with_capacity_zeroed_in(capacity, Global) in with_capacity_zeroed()
131 pub fn with_capacity_in(capacity: usize, alloc: A) -> Self { in with_capacity_in()
132 Self::allocate_in(capacity, AllocInit::Uninitialized, alloc) in with_capacity_in()
138 pub fn try_with_capacity_in(capacity: usize, alloc: A) -> Result<Self, TryReserveError> { in try_with_capacity_in()
139 Self::try_allocate_in(capacity, AllocInit::Uninitialized, alloc) in try_with_capacity_in()
146 pub fn with_capacity_zeroed_in(capacity: usize, alloc: A) -> Self { in with_capacity_zeroed_in()
147 Self::allocate_in(capacity, AllocInit::Zeroed, alloc) in with_capacity_zeroed_in()
157 /// * `len` must be greater than or equal to the most recently requested capacity, and
158 /// * `len` must be less than or equal to `self.capacity()`.
160 /// Note, that the requested capacity and `self.capacity()` could differ, as
165 len <= self.capacity(), in into_box()
166 "`len` must be smaller than or equal to `self.capacity()`" in into_box()
177 fn allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Self { in allocate_in()
178 // Don't allocate here because `Drop` will not deallocate when `capacity` is 0. in allocate_in()
179 if T::IS_ZST || capacity == 0 { in allocate_in()
184 let layout = match Layout::array::<T>(capacity) { in allocate_in()
202 // matches the size requested. If that ever changes, the capacity in allocate_in()
206 cap: capacity, in allocate_in()
212 … fn try_allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Result<Self, TryReserveError> { in try_allocate_in()
213 // Don't allocate here because `Drop` will not deallocate when `capacity` is 0. in try_allocate_in()
214 if T::IS_ZST || capacity == 0 { in try_allocate_in()
218 let layout = Layout::array::<T>(capacity).map_err(|_| CapacityOverflow)?; in try_allocate_in()
227 // matches the size requested. If that ever changes, the capacity in try_allocate_in()
231 cap: capacity, in try_allocate_in()
236 /// Reconstitutes a `RawVec` from a pointer, capacity, and allocator.
241 /// `capacity`.
242 /// The `capacity` cannot exceed `isize::MAX` for sized types. (only a concern on 32-bit
243 /// systems). ZST vectors may have a capacity up to `usize::MAX`.
244 /// If the `ptr` and `capacity` come from a `RawVec` created via `alloc`, then this is
247 pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, alloc: A) -> Self { in from_raw_parts_in()
248 Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc } in from_raw_parts_in()
252 /// `Unique::dangling()` if `capacity == 0` or `T` is zero-sized. In the former case, you must
259 /// Gets the capacity of the allocation.
263 pub fn capacity(&self) -> usize { in capacity() method
291 /// additional` elements. If it doesn't already have enough capacity, will
296 /// If `len` exceeds `self.capacity()`, this may fail to actually allocate
304 /// Panics if the new capacity exceeds `isize::MAX` bytes.
312 // Callers expect this function to be very cheap when there is already sufficient capacity. in reserve()
331 /// oft-instantiated `Vec::push()`, which does its own capacity check.
359 /// If `len` exceeds `self.capacity()`, this may fail to actually allocate
365 /// Panics if the new capacity exceeds `isize::MAX` bytes.
384 /// Shrinks the buffer down to the specified capacity. If the given amount
389 /// Panics if the given amount is *larger* than the current capacity.
401 /// Returns if the buffer needs to grow to fulfill the needed extra capacity.
404 additional > self.capacity().wrapping_sub(len) in needs_to_grow()
409 // the size requested. If that ever changes, the capacity here should in set_ptr_and_cap()
427 // Since we return a capacity of `usize::MAX` when `elem_size` is in grow_amortized()
453 // Since we return a capacity of `usize::MAX` when the type size is in grow_exact()
469 assert!(cap <= self.capacity(), "Tried to shrink to a larger capacity"); in shrink()
485 // overflowed earlier when capacity was larger. in shrink()
568 // One central function responsible for reporting capacity overflows. This'll
573 panic!("capacity overflow"); in capacity_overflow()