Lines Matching +full:cfg +full:- +full:space

1 // SPDX-License-Identifier: Apache-2.0 OR MIT
12 #[cfg(not(no_global_oom_handling))]
19 #[cfg(test)]
30 /// A low-level utility for more ergonomically allocating, reallocating, and deallocating
35 /// * Produces `Unique::dangling()` on zero-sized types.
36 /// * Produces `Unique::dangling()` on zero-length allocations.
39 /// * Guards against 32-bit systems allocating more than isize::MAX bytes.
49 /// Note that the excess of a zero-sized types is always infinite, so `capacity()` always returns
50 /// `usize::MAX`. This means that you need to be careful when round-tripping this type with a
64 /// that would truly const-call something unstable.
69 /// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a
73 pub const fn new() -> Self { in new()
80 /// zero-sized. Note that if `T` is zero-sized this means you will
90 #[cfg(not(any(no_global_oom_handling, test)))]
93 pub fn with_capacity(capacity: usize) -> Self { in with_capacity()
98 #[cfg(not(any(no_global_oom_handling, test)))]
101 pub fn with_capacity_zeroed(capacity: usize) -> Self { in with_capacity_zeroed()
108 // - 8 if the element size is 1, because any heap allocators is likely
110 // - 4 if elements are moderate-sized (<= 1 KiB).
111 // - 1 otherwise, to avoid wasting too much space for very short Vecs.
122 pub const fn new_in(alloc: A) -> Self { in new_in()
123 // `cap: 0` means "unallocated". zero-sized types are ignored. in new_in()
129 #[cfg(not(no_global_oom_handling))]
131 pub fn with_capacity_in(capacity: usize, alloc: A) -> Self { in with_capacity_in()
138 pub fn try_with_capacity_in(capacity: usize, alloc: A) -> Result<Self, TryReserveError> { in try_with_capacity_in()
144 #[cfg(not(no_global_oom_handling))]
146 pub fn with_capacity_zeroed_in(capacity: usize, alloc: A) -> Self { in with_capacity_zeroed_in()
162 pub unsafe fn into_box(self, len: usize) -> Box<[MaybeUninit<T>], A> { in into_box()
163 // Sanity-check one half of the safety requirement (we cannot check the other half). in into_box()
176 #[cfg(not(no_global_oom_handling))]
177 fn allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Self { in allocate_in()
212 … fn try_allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Result<Self, TryReserveError> { in try_allocate_in()
242 /// The `capacity` cannot exceed `isize::MAX` for sized types. (only a concern on 32-bit
247 pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, alloc: A) -> Self { in from_raw_parts_in()
252 /// `Unique::dangling()` if `capacity == 0` or `T` is zero-sized. In the former case, you must
255 pub fn ptr(&self) -> *mut T { in ptr()
261 /// This will always be `usize::MAX` if `T` is zero-sized.
263 pub fn capacity(&self) -> usize { in capacity()
268 pub fn allocator(&self) -> &A { in allocator()
272 fn current_memory(&self) -> Option<(NonNull<u8>, Layout)> { in current_memory()
290 /// Ensures that the buffer contains at least enough space to hold `len +
292 /// reallocate enough space plus comfortable slack space to get amortized
297 /// the requested space. This is not really unsafe, but the unsafe
300 /// This is ideal for implementing a bulk-push operation like `extend`.
309 #[cfg(not(no_global_oom_handling))]
313 // Therefore, we move all the resizing and error-handling logic from grow_amortized and in reserve()
331 /// oft-instantiated `Vec::push()`, which does its own capacity check.
332 #[cfg(not(no_global_oom_handling))]
339 pub fn try_reserve(&mut self, len: usize, additional: usize) -> Result<(), TryReserveError> { in try_reserve()
349 pub fn try_reserve_for_push(&mut self, len: usize) -> Result<(), TryReserveError> { in try_reserve_for_push()
353 /// Ensures that the buffer contains at least enough space to hold `len +
360 /// the requested space. This is not really unsafe, but the unsafe code
370 #[cfg(not(no_global_oom_handling))]
380 ) -> Result<(), TryReserveError> { in try_reserve_exact()
394 #[cfg(not(no_global_oom_handling))]
402 /// Mainly used to make inlining reserve-calls possible without inlining `grow`.
403 fn needs_to_grow(&self, len: usize, additional: usize) -> bool { in needs_to_grow()
421 // are non-generic over `T`.
422 fn grow_amortized(&mut self, len: usize, additional: usize) -> Result<(), TryReserveError> { in grow_amortized()
442 // `finish_grow` is non-generic over `T`. in grow_amortized()
451 fn grow_exact(&mut self, len: usize, additional: usize) -> Result<(), TryReserveError> { in grow_exact()
461 // `finish_grow` is non-generic over `T`. in grow_exact()
467 #[cfg(not(no_global_oom_handling))]
468 fn shrink(&mut self, cap: usize) -> Result<(), TryReserveError> { in shrink()
507 ) -> Result<NonNull<[u8]>, TryReserveError> in finish_grow()
540 #[cfg(not(no_global_oom_handling))]
551 // * We don't ever allocate `> isize::MAX` byte-size objects.
554 // On 64-bit we just need to check for overflow since trying to allocate
555 // `> isize::MAX` bytes will surely fail. On 32-bit and 16-bit we need to add
557 // all 4GB in user-space, e.g., PAE or x32.
560 fn alloc_guard(alloc_size: usize) -> Result<(), TryReserveError> { in alloc_guard()
571 #[cfg(not(no_global_oom_handling))]
572 fn capacity_overflow() -> ! { in capacity_overflow()