/rust/registry/src/index.crates.io-1949cf8c6b5b557f/smallvec-1.16.2/src/lib.rs
Line | Count | Source |
1 | | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
2 | | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
3 | | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
4 | | // option. This file may not be copied, modified, or distributed |
5 | | // except according to those terms. |
6 | | |
7 | | //! Small vectors in various sizes. These store a certain number of elements |
8 | | //! inline, and fall back to the heap for larger allocations. This can be a |
9 | | //! useful optimization for improving cache locality and reducing allocator |
10 | | //! traffic for workloads that fit within the inline buffer. |
11 | | //! |
12 | | //! ## `no_std` support |
13 | | //! |
14 | | //! By default, `smallvec` does not depend on `std`. However, the optional |
15 | | //! `write` feature implements the `std::io::Write` trait for vectors of `u8`. |
16 | | //! When this feature is enabled, `smallvec` depends on `std`. |
17 | | //! |
18 | | //! ## Optional features |
19 | | //! |
20 | | //! ### `serde` |
21 | | //! |
22 | | //! When this optional dependency is enabled, `SmallVec` implements the |
23 | | //! `serde::Serialize` and `serde::Deserialize` traits. |
24 | | //! |
25 | | //! ### `write` |
26 | | //! |
27 | | //! When this feature is enabled, `SmallVec<[u8; _]>` implements the |
28 | | //! `std::io::Write` trait. This feature is not compatible with `#![no_std]` |
29 | | //! programs. |
30 | | //! |
31 | | //! ### `union` |
32 | | //! |
33 | | //! **This feature requires Rust 1.49.** |
34 | | //! |
35 | | //! When the `union` feature is enabled `smallvec` will track its state (inline |
36 | | //! or spilled) without the use of an enum tag, reducing the size of the |
37 | | //! `smallvec` by one machine word. This means that there is potentially no |
38 | | //! space overhead compared to `Vec`. Note that `smallvec` can still be larger |
39 | | //! than `Vec` if the inline buffer is larger than two machine words. |
40 | | //! |
41 | | //! To use this feature add `features = ["union"]` in the `smallvec` section of |
42 | | //! Cargo.toml. Note that this feature requires Rust 1.49. |
43 | | //! |
44 | | //! Tracking issue: [rust-lang/rust#55149](https://github.com/rust-lang/rust/issues/55149) |
45 | | //! |
46 | | //! ### `const_generics` |
47 | | //! |
48 | | //! **This feature requires Rust 1.51.** |
49 | | //! |
50 | | //! When this feature is enabled, `SmallVec` works with any arrays of any size, |
51 | | //! not just a fixed list of sizes. |
52 | | //! |
53 | | //! ### `const_new` |
54 | | //! |
55 | | //! **This feature requires Rust 1.51.** |
56 | | //! |
57 | | //! This feature exposes the functions [`SmallVec::new_const`], |
58 | | //! [`SmallVec::from_const`], and [`smallvec_inline`] which enables the |
59 | | //! `SmallVec` to be initialized from a const context. For details, see the |
60 | | //! [Rust Reference](https://doc.rust-lang.org/reference/const_eval.html#const-functions). |
61 | | //! |
62 | | //! ### `drain_filter` |
63 | | //! |
64 | | //! **This feature is unstable.** It may change to match the unstable |
65 | | //! `drain_filter` method in libstd. |
66 | | //! |
67 | | //! Enables the `drain_filter` method, which produces an iterator that calls a |
68 | | //! user-provided closure to determine which elements of the vector to remove |
69 | | //! and yield from the iterator. |
70 | | //! |
71 | | //! ### `drain_keep_rest` |
72 | | //! |
73 | | //! **This feature is unstable.** It may change to match the unstable |
74 | | //! `drain_keep_rest` method in libstd. |
75 | | //! |
76 | | //! Enables the `DrainFilter::keep_rest` method. |
77 | | //! |
78 | | //! ### `specialization` |
79 | | //! |
80 | | //! **This feature is unstable and requires a nightly build of the Rust |
81 | | //! toolchain.** |
82 | | //! |
83 | | //! When this feature is enabled, `SmallVec::from(slice)` has improved |
84 | | //! performance for slices of `Copy` types. (Without this feature, you can use |
85 | | //! `SmallVec::from_slice` to get optimal performance for `Copy` types.) |
86 | | //! |
87 | | //! Tracking issue: [rust-lang/rust#31844](https://github.com/rust-lang/rust/issues/31844) |
88 | | //! |
89 | | //! ### `may_dangle` |
90 | | //! |
91 | | //! **This feature is unstable and requires a nightly build of the Rust |
92 | | //! toolchain.** |
93 | | //! |
94 | | //! This feature makes the Rust compiler less strict about use of vectors that |
95 | | //! contain borrowed references. For details, see the |
96 | | //! [Rustonomicon](https://doc.rust-lang.org/1.42.0/nomicon/dropck.html#an-escape-hatch). |
97 | | //! |
98 | | //! Tracking issue: [rust-lang/rust#34761](https://github.com/rust-lang/rust/issues/34761) |
99 | | |
100 | | #![no_std] |
101 | | #![cfg_attr(docsrs, feature(doc_cfg))] |
102 | | #![cfg_attr(feature = "specialization", allow(incomplete_features))] |
103 | | #![cfg_attr(feature = "specialization", feature(specialization))] |
104 | | #![cfg_attr(feature = "may_dangle", feature(dropck_eyepatch))] |
105 | | #![deny(missing_docs)] |
106 | | |
107 | | #[doc(hidden)] |
108 | | pub extern crate alloc; |
109 | | |
110 | | #[cfg(any(test, feature = "write"))] |
111 | | extern crate std; |
112 | | |
113 | | #[cfg(test)] |
114 | | mod tests; |
115 | | |
116 | | #[cfg(feature = "drain_keep_rest")] |
117 | | use core::mem::ManuallyDrop; |
118 | | #[cfg(feature = "malloc_size_of")] |
119 | | use malloc_size_of::{MallocShallowSizeOf, MallocSizeOf, MallocSizeOfOps}; |
120 | | #[cfg(feature = "serde")] |
121 | | use serde::{ |
122 | | de::{Deserialize, Deserializer, SeqAccess, Visitor}, |
123 | | ser::{Serialize, SerializeSeq, Serializer}, |
124 | | }; |
125 | | #[cfg(feature = "write")] |
126 | | use std::io; |
127 | | #[allow(deprecated)] |
128 | | use { |
129 | | alloc::{ |
130 | | alloc::{Layout, LayoutErr}, |
131 | | boxed::Box, |
132 | | vec, |
133 | | vec::Vec, |
134 | | }, |
135 | | core::{ |
136 | | borrow::{Borrow, BorrowMut}, |
137 | | cmp, fmt, |
138 | | hash::{Hash, Hasher}, |
139 | | hint::unreachable_unchecked, |
140 | | iter::{repeat, FromIterator, FusedIterator, IntoIterator}, |
141 | | marker::PhantomData, |
142 | | mem::{self, MaybeUninit}, |
143 | | ops::{self, Range, RangeBounds}, |
144 | | ptr::{self, NonNull}, |
145 | | slice::{self, SliceIndex}, |
146 | | }, |
147 | | }; |
148 | | |
149 | | /// Creates a [`SmallVec`] containing the arguments. |
150 | | /// |
151 | | /// `smallvec!` allows `SmallVec`s to be defined with the same syntax as array |
152 | | /// expressions. There are two forms of this macro: |
153 | | /// |
154 | | /// - Create a [`SmallVec`] containing a given list of elements: |
155 | | /// |
156 | | /// ``` |
157 | | /// # use smallvec::{smallvec, SmallVec}; |
158 | | /// # fn main() { |
159 | | /// let v: SmallVec<[_; 128]> = smallvec![1, 2, 3]; |
160 | | /// assert_eq!(v[0], 1); |
161 | | /// assert_eq!(v[1], 2); |
162 | | /// assert_eq!(v[2], 3); |
163 | | /// # } |
164 | | /// ``` |
165 | | /// |
166 | | /// - Create a [`SmallVec`] from a given element and size: |
167 | | /// |
168 | | /// ``` |
169 | | /// # use smallvec::{smallvec, SmallVec}; |
170 | | /// # fn main() { |
171 | | /// let v: SmallVec<[_; 10]> = smallvec![1; 3]; |
172 | | /// assert_eq!(v, SmallVec::from_buf([1, 1, 1])); |
173 | | /// # } |
174 | | /// ``` |
175 | | /// |
176 | | /// Note that unlike array expressions this syntax supports all elements |
177 | | /// which implement [`Clone`] and the number of elements doesn't have to be |
178 | | /// a constant. |
179 | | /// |
180 | | /// This will use `clone` to duplicate an expression, so one should be careful |
181 | | /// using this with types having a nonstandard `Clone` implementation. For |
182 | | /// example, `smallvec![Rc::new(1); 5]` will create a vector of five references |
183 | | /// to the same boxed integer value, not five references pointing to |
184 | | /// independently boxed integers. |
185 | | #[macro_export] |
186 | | macro_rules! smallvec { |
187 | | // count helper: transform any expression into 1 |
188 | | (@one $x:expr) => (1usize); |
189 | | () => ( |
190 | | $crate::SmallVec::new() |
191 | | ); |
192 | | ($elem:expr; $n:expr) => ({ |
193 | | $crate::SmallVec::from_elem($elem, $n) |
194 | | }); |
195 | | ($($x:expr),+$(,)?) => ({ |
196 | | let count = 0usize $(+ $crate::smallvec!(@one $x))+; |
197 | | let mut vec = $crate::SmallVec::new(); |
198 | | if count <= vec.inline_size() { |
199 | | $(vec.push($x);)* |
200 | | vec |
201 | | } else { |
202 | | $crate::SmallVec::from_vec($crate::alloc::vec![$($x,)+]) |
203 | | } |
204 | | }); |
205 | | } |
206 | | |
207 | | /// Creates an inline [`SmallVec`] containing the arguments. This macro is |
208 | | /// enabled by the feature `const_new`. |
209 | | /// |
210 | | /// `smallvec_inline!` allows `SmallVec`s to be defined with the same syntax as |
211 | | /// array expressions in `const` contexts. The inline storage `A` will always be |
212 | | /// an array of the size specified by the arguments. There are two forms of this |
213 | | /// macro: |
214 | | /// |
215 | | /// - Create a [`SmallVec`] containing a given list of elements: |
216 | | /// |
217 | | /// ``` |
218 | | /// # use smallvec::{smallvec_inline, SmallVec}; |
219 | | /// # fn main() { |
220 | | /// const V: SmallVec<[i32; 3]> = smallvec_inline![1, 2, 3]; |
221 | | /// assert_eq!(V[0], 1); |
222 | | /// assert_eq!(V[1], 2); |
223 | | /// assert_eq!(V[2], 3); |
224 | | /// # } |
225 | | /// ``` |
226 | | /// |
227 | | /// - Create a [`SmallVec`] from a given element and size: |
228 | | /// |
229 | | /// ``` |
230 | | /// # use smallvec::{smallvec_inline, SmallVec}; |
231 | | /// # fn main() { |
232 | | /// const V: SmallVec<[i32; 3]> = smallvec_inline![1; 3]; |
233 | | /// assert_eq!(V, SmallVec::from_buf([1, 1, 1])); |
234 | | /// # } |
235 | | /// ``` |
236 | | /// |
237 | | /// Note that the behavior mimics that of array expressions, in contrast to |
238 | | /// [`smallvec`]. |
239 | | #[cfg(feature = "const_new")] |
240 | | #[cfg_attr(docsrs, doc(cfg(feature = "const_new")))] |
241 | | #[macro_export] |
242 | | macro_rules! smallvec_inline { |
243 | | // count helper: transform any expression into 1 |
244 | | (@one $x:expr) => (1usize); |
245 | | ($elem:expr; $n:expr) => ({ |
246 | | $crate::SmallVec::<[_; $n]>::from_const([$elem; $n]) |
247 | | }); |
248 | | ($($x:expr),+ $(,)?) => ({ |
249 | | const N: usize = 0usize $(+ $crate::smallvec_inline!(@one $x))*; |
250 | | $crate::SmallVec::<[_; N]>::from_const([$($x,)*]) |
251 | | }); |
252 | | } |
253 | | |
254 | | /// `panic!()` in debug builds, optimization hint in release. |
255 | | #[cfg(not(feature = "union"))] |
256 | | macro_rules! debug_unreachable { |
257 | | () => { |
258 | | debug_unreachable!("entered unreachable code") |
259 | | }; |
260 | | ($e:expr) => { |
261 | | if cfg!(debug_assertions) { |
262 | | panic!($e); |
263 | | } else { |
264 | | unreachable_unchecked(); |
265 | | } |
266 | | }; |
267 | | } |
268 | | |
269 | | /// Trait to be implemented by a collection that can be extended from a slice |
270 | | /// |
271 | | /// ## Example |
272 | | /// |
273 | | /// ```rust |
274 | | /// use smallvec::{ExtendFromSlice, SmallVec}; |
275 | | /// |
276 | | /// fn initialize<V: ExtendFromSlice<u8>>(v: &mut V) { |
277 | | /// v.extend_from_slice(b"Test!"); |
278 | | /// } |
279 | | /// |
280 | | /// let mut vec = Vec::new(); |
281 | | /// initialize(&mut vec); |
282 | | /// assert_eq!(&vec, b"Test!"); |
283 | | /// |
284 | | /// let mut small_vec = SmallVec::<[u8; 8]>::new(); |
285 | | /// initialize(&mut small_vec); |
286 | | /// assert_eq!(&small_vec as &[_], b"Test!"); |
287 | | /// ``` |
288 | | #[doc(hidden)] |
289 | | #[deprecated] |
290 | | pub trait ExtendFromSlice<T> { |
291 | | /// Extends a collection from a slice of its element type |
292 | | fn extend_from_slice(&mut self, other: &[T]); |
293 | | } |
294 | | |
295 | | #[allow(deprecated)] |
296 | | impl<T: Clone> ExtendFromSlice<T> for Vec<T> { |
297 | 0 | fn extend_from_slice(&mut self, other: &[T]) { |
298 | 0 | Vec::extend_from_slice(self, other) |
299 | 0 | } |
300 | | } |
301 | | |
302 | | /// Error type for APIs with fallible heap allocation |
303 | | #[derive(Debug)] |
304 | | pub enum CollectionAllocErr { |
305 | | /// Overflow `usize::MAX` or other error during size computation |
306 | | CapacityOverflow, |
307 | | /// The allocator return an error |
308 | | AllocErr { |
309 | | /// The layout that was passed to the allocator |
310 | | layout: Layout, |
311 | | }, |
312 | | } |
313 | | |
314 | | impl fmt::Display for CollectionAllocErr { |
315 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
316 | 0 | write!(f, "Allocation error: {:?}", self) |
317 | 0 | } |
318 | | } |
319 | | |
320 | | #[allow(deprecated)] |
321 | | impl From<LayoutErr> for CollectionAllocErr { |
322 | 0 | fn from(_: LayoutErr) -> Self { |
323 | 0 | CollectionAllocErr::CapacityOverflow |
324 | 0 | } |
325 | | } |
326 | | |
327 | 10.0M | fn infallible<T>(result: Result<T, CollectionAllocErr>) -> T { |
328 | 0 | match result { |
329 | 10.0M | Ok(x) => x, |
330 | 0 | Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"), |
331 | 0 | Err(CollectionAllocErr::AllocErr { layout }) => alloc::alloc::handle_alloc_error(layout), |
332 | | } |
333 | 10.0M | } smallvec::infallible::<()> Line | Count | Source | 327 | 10.0M | fn infallible<T>(result: Result<T, CollectionAllocErr>) -> T { | 328 | 0 | match result { | 329 | 10.0M | Ok(x) => x, | 330 | 0 | Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"), | 331 | 0 | Err(CollectionAllocErr::AllocErr { layout }) => alloc::alloc::handle_alloc_error(layout), | 332 | | } | 333 | 10.0M | } |
Unexecuted instantiation: smallvec::infallible::<_> |
334 | | |
335 | | /// FIXME: use `Layout::array` when we require a Rust version where it’s stable |
336 | | /// <https://github.com/rust-lang/rust/issues/55724> |
337 | 1.20M | fn layout_array<T>(n: usize) -> Result<Layout, CollectionAllocErr> { |
338 | 1.20M | let size = mem::size_of::<T>() |
339 | 1.20M | .checked_mul(n) |
340 | 1.20M | .ok_or(CollectionAllocErr::CapacityOverflow)?; |
341 | 1.20M | let align = mem::align_of::<T>(); |
342 | 1.20M | Layout::from_size_align(size, align).map_err(|_| CollectionAllocErr::CapacityOverflow) |
343 | 1.20M | } smallvec::layout_array::<alloc::vec::Vec<u64>> Line | Count | Source | 337 | 2.53k | fn layout_array<T>(n: usize) -> Result<Layout, CollectionAllocErr> { | 338 | 2.53k | let size = mem::size_of::<T>() | 339 | 2.53k | .checked_mul(n) | 340 | 2.53k | .ok_or(CollectionAllocErr::CapacityOverflow)?; | 341 | 2.53k | let align = mem::align_of::<T>(); | 342 | 2.53k | Layout::from_size_align(size, align).map_err(|_| CollectionAllocErr::CapacityOverflow) | 343 | 2.53k | } |
smallvec::layout_array::<exr::meta::header::Header> Line | Count | Source | 337 | 5.71k | fn layout_array<T>(n: usize) -> Result<Layout, CollectionAllocErr> { | 338 | 5.71k | let size = mem::size_of::<T>() | 339 | 5.71k | .checked_mul(n) | 340 | 5.71k | .ok_or(CollectionAllocErr::CapacityOverflow)?; | 341 | 5.71k | let align = mem::align_of::<T>(); | 342 | 5.71k | Layout::from_size_align(size, align).map_err(|_| CollectionAllocErr::CapacityOverflow) | 343 | 5.71k | } |
smallvec::layout_array::<exr::meta::attribute::ChannelDescription> Line | Count | Source | 337 | 5.93k | fn layout_array<T>(n: usize) -> Result<Layout, CollectionAllocErr> { | 338 | 5.93k | let size = mem::size_of::<T>() | 339 | 5.93k | .checked_mul(n) | 340 | 5.93k | .ok_or(CollectionAllocErr::CapacityOverflow)?; | 341 | 5.93k | let align = mem::align_of::<T>(); | 342 | 5.93k | Layout::from_size_align(size, align).map_err(|_| CollectionAllocErr::CapacityOverflow) | 343 | 5.93k | } |
Unexecuted instantiation: smallvec::layout_array::<exr::image::AnyChannel<exr::image::FlatSamples>> Unexecuted instantiation: smallvec::layout_array::<exr::compression::piz::ChannelData> Unexecuted instantiation: smallvec::layout_array::<exr::block::samples::Sample> smallvec::layout_array::<u8> Line | Count | Source | 337 | 1.19M | fn layout_array<T>(n: usize) -> Result<Layout, CollectionAllocErr> { | 338 | 1.19M | let size = mem::size_of::<T>() | 339 | 1.19M | .checked_mul(n) | 340 | 1.19M | .ok_or(CollectionAllocErr::CapacityOverflow)?; | 341 | 1.19M | let align = mem::align_of::<T>(); | 342 | 1.19M | Layout::from_size_align(size, align).map_err(|_| CollectionAllocErr::CapacityOverflow) | 343 | 1.19M | } |
Unexecuted instantiation: smallvec::layout_array::<usize> smallvec::layout_array::<u32> Line | Count | Source | 337 | 273 | fn layout_array<T>(n: usize) -> Result<Layout, CollectionAllocErr> { | 338 | 273 | let size = mem::size_of::<T>() | 339 | 273 | .checked_mul(n) | 340 | 273 | .ok_or(CollectionAllocErr::CapacityOverflow)?; | 341 | 273 | let align = mem::align_of::<T>(); | 342 | 273 | Layout::from_size_align(size, align).map_err(|_| CollectionAllocErr::CapacityOverflow) | 343 | 273 | } |
Unexecuted instantiation: smallvec::layout_array::<_> |
344 | | |
345 | 0 | unsafe fn deallocate<T>(ptr: NonNull<T>, capacity: usize) { |
346 | | // This unwrap should succeed since the same did when allocating. |
347 | 0 | let layout = layout_array::<T>(capacity).unwrap(); |
348 | 0 | alloc::alloc::dealloc(ptr.as_ptr() as *mut u8, layout) |
349 | 0 | } Unexecuted instantiation: smallvec::deallocate::<alloc::vec::Vec<u64>> Unexecuted instantiation: smallvec::deallocate::<exr::meta::header::Header> Unexecuted instantiation: smallvec::deallocate::<exr::meta::attribute::ChannelDescription> Unexecuted instantiation: smallvec::deallocate::<exr::image::AnyChannel<exr::image::FlatSamples>> Unexecuted instantiation: smallvec::deallocate::<exr::compression::piz::ChannelData> Unexecuted instantiation: smallvec::deallocate::<exr::block::samples::Sample> Unexecuted instantiation: smallvec::deallocate::<u8> Unexecuted instantiation: smallvec::deallocate::<usize> Unexecuted instantiation: smallvec::deallocate::<u32> Unexecuted instantiation: smallvec::deallocate::<_> |
350 | | |
351 | | /// An iterator that removes the items from a `SmallVec` and yields them by |
352 | | /// value. |
353 | | /// |
354 | | /// Returned from [`SmallVec::drain`][1]. |
355 | | /// |
356 | | /// [1]: struct.SmallVec.html#method.drain |
357 | | pub struct Drain<'a, T: 'a + Array> { |
358 | | tail_start: usize, |
359 | | tail_len: usize, |
360 | | iter: slice::Iter<'a, T::Item>, |
361 | | vec: NonNull<SmallVec<T>>, |
362 | | } |
363 | | |
364 | | impl<'a, T: 'a + Array> fmt::Debug for Drain<'a, T> |
365 | | where |
366 | | T::Item: fmt::Debug, |
367 | | { |
368 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
369 | 0 | f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() |
370 | 0 | } |
371 | | } |
372 | | |
373 | | unsafe impl<'a, T: Sync + Array> Sync for Drain<'a, T> {} |
374 | | unsafe impl<'a, T: Send + Array> Send for Drain<'a, T> {} |
375 | | |
376 | | impl<'a, T: 'a + Array> Iterator for Drain<'a, T> { |
377 | | type Item = T::Item; |
378 | | |
379 | | #[inline] |
380 | 0 | fn next(&mut self) -> Option<T::Item> { |
381 | 0 | self.iter |
382 | 0 | .next() |
383 | 0 | .map(|reference| unsafe { ptr::read(reference) }) |
384 | 0 | } |
385 | | |
386 | | #[inline] |
387 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
388 | 0 | self.iter.size_hint() |
389 | 0 | } |
390 | | } |
391 | | |
392 | | impl<'a, T: 'a + Array> DoubleEndedIterator for Drain<'a, T> { |
393 | | #[inline] |
394 | 0 | fn next_back(&mut self) -> Option<T::Item> { |
395 | 0 | self.iter |
396 | 0 | .next_back() |
397 | 0 | .map(|reference| unsafe { ptr::read(reference) }) |
398 | 0 | } |
399 | | } |
400 | | |
401 | | impl<'a, T: Array> ExactSizeIterator for Drain<'a, T> { |
402 | | #[inline] |
403 | 0 | fn len(&self) -> usize { |
404 | 0 | self.iter.len() |
405 | 0 | } |
406 | | } |
407 | | |
408 | | impl<'a, T: Array> FusedIterator for Drain<'a, T> {} |
409 | | |
410 | | impl<'a, T: 'a + Array> Drop for Drain<'a, T> { |
411 | 0 | fn drop(&mut self) { |
412 | 0 | self.for_each(drop); |
413 | | |
414 | 0 | if self.tail_len > 0 { |
415 | | unsafe { |
416 | 0 | let source_vec = self.vec.as_mut(); |
417 | | |
418 | | // memmove back untouched tail, update to new length |
419 | 0 | let start = source_vec.len(); |
420 | 0 | let tail = self.tail_start; |
421 | 0 | if tail != start { |
422 | 0 | // as_mut_ptr creates a &mut, invalidating other pointers. |
423 | 0 | // This pattern avoids calling it with a pointer already |
424 | 0 | // present. |
425 | 0 | let ptr = source_vec.as_mut_ptr(); |
426 | 0 | let src = ptr.add(tail); |
427 | 0 | let dst = ptr.add(start); |
428 | 0 | ptr::copy(src, dst, self.tail_len); |
429 | 0 | } |
430 | 0 | source_vec.set_len(start + self.tail_len); |
431 | | } |
432 | 0 | } |
433 | 0 | } |
434 | | } |
435 | | |
436 | | #[cfg(feature = "drain_filter")] |
437 | | /// An iterator which uses a closure to determine if an element should be |
438 | | /// removed. |
439 | | /// |
440 | | /// Returned from [`SmallVec::drain_filter`][1]. |
441 | | /// |
442 | | /// [1]: struct.SmallVec.html#method.drain_filter |
443 | | pub struct DrainFilter<'a, T, F> |
444 | | where |
445 | | F: FnMut(&mut T::Item) -> bool, |
446 | | T: Array, |
447 | | { |
448 | | vec: &'a mut SmallVec<T>, |
449 | | /// The index of the item that will be inspected by the next call to `next`. |
450 | | idx: usize, |
451 | | /// The number of items that have been drained (removed) thus far. |
452 | | del: usize, |
453 | | /// The original length of `vec` prior to draining. |
454 | | old_len: usize, |
455 | | /// The filter test predicate. |
456 | | pred: F, |
457 | | /// A flag that indicates a panic has occurred in the filter test predicate. |
458 | | /// This is used as a hint in the drop implementation to prevent consumption |
459 | | /// of the remainder of the `DrainFilter`. Any unprocessed items will be |
460 | | /// backshifted in the `vec`, but no further items will be dropped or |
461 | | /// tested by the filter predicate. |
462 | | panic_flag: bool, |
463 | | } |
464 | | |
465 | | #[cfg(feature = "drain_filter")] |
466 | | impl<T, F> fmt::Debug for DrainFilter<'_, T, F> |
467 | | where |
468 | | F: FnMut(&mut T::Item) -> bool, |
469 | | T: Array, |
470 | | T::Item: fmt::Debug, |
471 | | { |
472 | | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
473 | | f.debug_tuple("DrainFilter") |
474 | | .field(&self.vec.as_slice()) |
475 | | .finish() |
476 | | } |
477 | | } |
478 | | |
479 | | #[cfg(feature = "drain_filter")] |
480 | | impl<T, F> Iterator for DrainFilter<'_, T, F> |
481 | | where |
482 | | F: FnMut(&mut T::Item) -> bool, |
483 | | T: Array, |
484 | | { |
485 | | type Item = T::Item; |
486 | | |
487 | | fn next(&mut self) -> Option<T::Item> { |
488 | | unsafe { |
489 | | while self.idx < self.old_len { |
490 | | let i = self.idx; |
491 | | let v = slice::from_raw_parts_mut(self.vec.as_mut_ptr(), self.old_len); |
492 | | self.panic_flag = true; |
493 | | let drained = (self.pred)(&mut v[i]); |
494 | | self.panic_flag = false; |
495 | | // Update the index *after* the predicate is called. If the |
496 | | // index is updated prior and the predicate |
497 | | // panics, the element at this index would be |
498 | | // leaked. |
499 | | self.idx += 1; |
500 | | if drained { |
501 | | self.del += 1; |
502 | | return Some(ptr::read(&v[i])); |
503 | | } else if self.del > 0 { |
504 | | let del = self.del; |
505 | | let src: *const Self::Item = &v[i]; |
506 | | let dst: *mut Self::Item = &mut v[i - del]; |
507 | | ptr::copy_nonoverlapping(src, dst, 1); |
508 | | } |
509 | | } |
510 | | None |
511 | | } |
512 | | } |
513 | | |
514 | | fn size_hint(&self) -> (usize, Option<usize>) { |
515 | | (0, Some(self.old_len - self.idx)) |
516 | | } |
517 | | } |
518 | | |
519 | | #[cfg(feature = "drain_filter")] |
520 | | impl<T, F> Drop for DrainFilter<'_, T, F> |
521 | | where |
522 | | F: FnMut(&mut T::Item) -> bool, |
523 | | T: Array, |
524 | | { |
525 | | fn drop(&mut self) { |
526 | | struct BackshiftOnDrop<'a, 'b, T, F> |
527 | | where |
528 | | F: FnMut(&mut T::Item) -> bool, |
529 | | T: Array, |
530 | | { |
531 | | drain: &'b mut DrainFilter<'a, T, F>, |
532 | | } |
533 | | |
534 | | impl<'a, 'b, T, F> Drop for BackshiftOnDrop<'a, 'b, T, F> |
535 | | where |
536 | | F: FnMut(&mut T::Item) -> bool, |
537 | | T: Array, |
538 | | { |
539 | | fn drop(&mut self) { |
540 | | unsafe { |
541 | | if self.drain.idx < self.drain.old_len && self.drain.del > 0 { |
542 | | // This is a pretty messed up state, and there isn't |
543 | | // really an obviously right |
544 | | // thing to do. We don't want to keep trying |
545 | | // to execute `pred`, so we just backshift all the |
546 | | // unprocessed elements and tell |
547 | | // the vec that they still exist. The backshift |
548 | | // is required to prevent a double-drop of the last |
549 | | // successfully drained item |
550 | | // prior to a panic in the predicate. |
551 | | let ptr = self.drain.vec.as_mut_ptr(); |
552 | | let src = ptr.add(self.drain.idx); |
553 | | let dst = src.sub(self.drain.del); |
554 | | let tail_len = self.drain.old_len - self.drain.idx; |
555 | | src.copy_to(dst, tail_len); |
556 | | } |
557 | | self.drain.vec.set_len(self.drain.old_len - self.drain.del); |
558 | | } |
559 | | } |
560 | | } |
561 | | |
562 | | let backshift = BackshiftOnDrop { drain: self }; |
563 | | |
564 | | // Attempt to consume any remaining elements if the filter predicate |
565 | | // has not yet panicked. We'll backshift any remaining elements |
566 | | // whether we've already panicked or if the consumption here panics. |
567 | | if !backshift.drain.panic_flag { |
568 | | backshift.drain.for_each(drop); |
569 | | } |
570 | | } |
571 | | } |
572 | | |
573 | | #[cfg(feature = "drain_keep_rest")] |
574 | | impl<T, F> DrainFilter<'_, T, F> |
575 | | where |
576 | | F: FnMut(&mut T::Item) -> bool, |
577 | | T: Array, |
578 | | { |
579 | | /// Keep unyielded elements in the source `Vec`. |
580 | | /// |
581 | | /// # Examples |
582 | | /// |
583 | | /// ``` |
584 | | /// # use smallvec::{smallvec, SmallVec}; |
585 | | /// |
586 | | /// let mut vec: SmallVec<[char; 2]> = smallvec!['a', 'b', 'c']; |
587 | | /// let mut drain = vec.drain_filter(|_| true); |
588 | | /// |
589 | | /// assert_eq!(drain.next().unwrap(), 'a'); |
590 | | /// |
591 | | /// // This call keeps 'b' and 'c' in the vec. |
592 | | /// drain.keep_rest(); |
593 | | /// |
594 | | /// // If we wouldn't call `keep_rest()`, |
595 | | /// // `vec` would be empty. |
596 | | /// assert_eq!(vec, SmallVec::<[char; 2]>::from_slice(&['b', 'c'])); |
597 | | /// ``` |
598 | | pub fn keep_rest(self) { |
599 | | // At this moment layout looks like this: |
600 | | // |
601 | | // _____________________/-- old_len |
602 | | // / \ |
603 | | // [kept] [yielded] [tail] |
604 | | // \_______/ ^-- idx |
605 | | // \-- del |
606 | | // |
607 | | // Normally `Drop` impl would drop [tail] (via .for_each(drop), ie still |
608 | | // calling `pred`) |
609 | | // |
610 | | // 1. Move [tail] after [kept] |
611 | | // 2. Update length of the original vec to `old_len - del` a. In case of |
612 | | // ZST, this is the only thing we want to do |
613 | | // 3. Do *not* drop self, as everything is put in a consistent state |
614 | | // already, there is nothing to do |
615 | | let mut this = ManuallyDrop::new(self); |
616 | | |
617 | | unsafe { |
618 | | // ZSTs have no identity, so we don't need to move them around. |
619 | | let needs_move = mem::size_of::<T::Item>() != 0; |
620 | | |
621 | | if needs_move && this.idx < this.old_len && this.del > 0 { |
622 | | let ptr = this.vec.as_mut_ptr(); |
623 | | let src = ptr.add(this.idx); |
624 | | let dst = src.sub(this.del); |
625 | | let tail_len = this.old_len - this.idx; |
626 | | src.copy_to(dst, tail_len); |
627 | | } |
628 | | |
629 | | let new_len = this.old_len - this.del; |
630 | | this.vec.set_len(new_len); |
631 | | } |
632 | | } |
633 | | } |
634 | | |
635 | | #[cfg(feature = "union")] |
636 | | union SmallVecData<A: Array> { |
637 | | inline: core::mem::ManuallyDrop<MaybeUninit<A>>, |
638 | | heap: (NonNull<A::Item>, usize), |
639 | | } |
640 | | |
641 | | #[cfg(all(feature = "union", feature = "const_new"))] |
642 | | impl<T, const N: usize> SmallVecData<[T; N]> { |
643 | | #[cfg_attr(docsrs, doc(cfg(feature = "const_new")))] |
644 | | #[inline] |
645 | | const fn from_const(inline: MaybeUninit<[T; N]>) -> Self { |
646 | | SmallVecData { |
647 | | inline: core::mem::ManuallyDrop::new(inline), |
648 | | } |
649 | | } |
650 | | } |
651 | | |
652 | | #[cfg(feature = "union")] |
653 | | impl<A: Array> SmallVecData<A> { |
654 | | #[inline] |
655 | | unsafe fn inline(&self) -> ConstNonNull<A::Item> { |
656 | | ConstNonNull::new(self.inline.as_ptr() as *const A::Item).unwrap() |
657 | | } |
658 | | #[inline] |
659 | | unsafe fn inline_mut(&mut self) -> NonNull<A::Item> { |
660 | | NonNull::new(self.inline.as_mut_ptr() as *mut A::Item).unwrap() |
661 | | } |
662 | | #[inline] |
663 | | fn from_inline(inline: MaybeUninit<A>) -> SmallVecData<A> { |
664 | | SmallVecData { |
665 | | inline: core::mem::ManuallyDrop::new(inline), |
666 | | } |
667 | | } |
668 | | // Workaround for https://github.com/rust-lang/rust/issues/157743: when from_inline is |
669 | | // called with MaybeUninit::uninit(), rustc 1.93+ GVN propagates const |
670 | | // <uninit> into the ManuallyDrop::new() aggregate, causing LLVM to |
671 | | // materialize a global constant that MemCpyOpt then collapses into a |
672 | | // memset over the whole struct. Using assume_init() of a doubly-wrapped |
673 | | // MaybeUninit produces Immediate::Uninit instead of const <uninit>, |
674 | | // which codegen handles as undef without emitting any global. This |
675 | | // function also avoids introducing an intermediate local that would |
676 | | // inflate stack frames in debug builds. |
677 | | #[inline] |
678 | | fn empty() -> SmallVecData<A> { |
679 | | // SAFETY: ManuallyDrop<MaybeUninit<A>> is valid for any bit pattern |
680 | | // including uninitialized bytes, so assume_init() on a |
681 | | // MaybeUninit of that type is sound. |
682 | | SmallVecData { |
683 | | inline: unsafe { MaybeUninit::uninit().assume_init() }, |
684 | | } |
685 | | } |
686 | | #[inline] |
687 | | unsafe fn into_inline(self) -> MaybeUninit<A> { |
688 | | core::mem::ManuallyDrop::into_inner(self.inline) |
689 | | } |
690 | | #[inline] |
691 | | unsafe fn heap(&self) -> (ConstNonNull<A::Item>, usize) { |
692 | | (ConstNonNull(self.heap.0), self.heap.1) |
693 | | } |
694 | | #[inline] |
695 | | unsafe fn heap_mut(&mut self) -> (NonNull<A::Item>, &mut usize) { |
696 | | let h = &mut self.heap; |
697 | | (h.0, &mut h.1) |
698 | | } |
699 | | #[inline] |
700 | | fn from_heap(ptr: NonNull<A::Item>, len: usize) -> SmallVecData<A> { |
701 | | SmallVecData { heap: (ptr, len) } |
702 | | } |
703 | | } |
704 | | |
705 | | #[cfg(not(feature = "union"))] |
706 | | enum SmallVecData<A: Array> { |
707 | | Inline(MaybeUninit<A>), |
708 | | // Using NonNull and NonZero here allows to reduce size of `SmallVec`. |
709 | | Heap { |
710 | | // Since we never allocate on heap |
711 | | // unless our capacity is bigger than inline capacity |
712 | | // heap capacity cannot be less than 1. |
713 | | // Therefore, pointer cannot be null too. |
714 | | ptr: NonNull<A::Item>, |
715 | | len: usize, |
716 | | }, |
717 | | } |
718 | | |
719 | | #[cfg(all(not(feature = "union"), feature = "const_new"))] |
720 | | impl<T, const N: usize> SmallVecData<[T; N]> { |
721 | | #[cfg_attr(docsrs, doc(cfg(feature = "const_new")))] |
722 | | #[inline] |
723 | | const fn from_const(inline: MaybeUninit<[T; N]>) -> Self { |
724 | | SmallVecData::Inline(inline) |
725 | | } |
726 | | } |
727 | | |
728 | | #[cfg(not(feature = "union"))] |
729 | | impl<A: Array> SmallVecData<A> { |
730 | | #[inline] |
731 | 61.1M | unsafe fn inline(&self) -> ConstNonNull<A::Item> { |
732 | 61.1M | match self { |
733 | 61.1M | SmallVecData::Inline(a) => ConstNonNull::new(a.as_ptr() as *const A::Item).unwrap(), |
734 | 0 | _ => debug_unreachable!(), |
735 | | } |
736 | 61.1M | } <smallvec::SmallVecData<[u8; 64]>>::inline Line | Count | Source | 731 | 10.0M | unsafe fn inline(&self) -> ConstNonNull<A::Item> { | 732 | 10.0M | match self { | 733 | 10.0M | SmallVecData::Inline(a) => ConstNonNull::new(a.as_ptr() as *const A::Item).unwrap(), | 734 | 0 | _ => debug_unreachable!(), | 735 | | } | 736 | 10.0M | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::inline <smallvec::SmallVecData<[alloc::vec::Vec<u64>; 3]>>::inline Line | Count | Source | 731 | 1.63M | unsafe fn inline(&self) -> ConstNonNull<A::Item> { | 732 | 1.63M | match self { | 733 | 1.63M | SmallVecData::Inline(a) => ConstNonNull::new(a.as_ptr() as *const A::Item).unwrap(), | 734 | 0 | _ => debug_unreachable!(), | 735 | | } | 736 | 1.63M | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::compression::piz::ChannelData; 6]>>::inline <smallvec::SmallVecData<[exr::meta::header::Header; 3]>>::inline Line | Count | Source | 731 | 6.14M | unsafe fn inline(&self) -> ConstNonNull<A::Item> { | 732 | 6.14M | match self { | 733 | 6.14M | SmallVecData::Inline(a) => ConstNonNull::new(a.as_ptr() as *const A::Item).unwrap(), | 734 | 0 | _ => debug_unreachable!(), | 735 | | } | 736 | 6.14M | } |
<smallvec::SmallVecData<[exr::meta::attribute::ChannelDescription; 5]>>::inline Line | Count | Source | 731 | 1.20M | unsafe fn inline(&self) -> ConstNonNull<A::Item> { | 732 | 1.20M | match self { | 733 | 1.20M | SmallVecData::Inline(a) => ConstNonNull::new(a.as_ptr() as *const A::Item).unwrap(), | 734 | 0 | _ => debug_unreachable!(), | 735 | | } | 736 | 1.20M | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::block::samples::Sample; 8]>>::inline <smallvec::SmallVecData<[u8; 16]>>::inline Line | Count | Source | 731 | 132k | unsafe fn inline(&self) -> ConstNonNull<A::Item> { | 732 | 132k | match self { | 733 | 132k | SmallVecData::Inline(a) => ConstNonNull::new(a.as_ptr() as *const A::Item).unwrap(), | 734 | 0 | _ => debug_unreachable!(), | 735 | | } | 736 | 132k | } |
<smallvec::SmallVecData<[u8; 24]>>::inline Line | Count | Source | 731 | 41.9M | unsafe fn inline(&self) -> ConstNonNull<A::Item> { | 732 | 41.9M | match self { | 733 | 41.9M | SmallVecData::Inline(a) => ConstNonNull::new(a.as_ptr() as *const A::Item).unwrap(), | 734 | 0 | _ => debug_unreachable!(), | 735 | | } | 736 | 41.9M | } |
<smallvec::SmallVecData<[u8; 8]>>::inline Line | Count | Source | 731 | 26.4k | unsafe fn inline(&self) -> ConstNonNull<A::Item> { | 732 | 26.4k | match self { | 733 | 26.4k | SmallVecData::Inline(a) => ConstNonNull::new(a.as_ptr() as *const A::Item).unwrap(), | 734 | 0 | _ => debug_unreachable!(), | 735 | | } | 736 | 26.4k | } |
Unexecuted instantiation: <smallvec::SmallVecData<[usize; 8]>>::inline <smallvec::SmallVecData<[u32; 2]>>::inline Line | Count | Source | 731 | 1.07k | unsafe fn inline(&self) -> ConstNonNull<A::Item> { | 732 | 1.07k | match self { | 733 | 1.07k | SmallVecData::Inline(a) => ConstNonNull::new(a.as_ptr() as *const A::Item).unwrap(), | 734 | 0 | _ => debug_unreachable!(), | 735 | | } | 736 | 1.07k | } |
Unexecuted instantiation: <smallvec::SmallVecData<_>>::inline |
737 | | #[inline] |
738 | 67.7M | unsafe fn inline_mut(&mut self) -> NonNull<A::Item> { |
739 | 67.7M | match self { |
740 | 67.7M | SmallVecData::Inline(a) => NonNull::new(a.as_mut_ptr() as *mut A::Item).unwrap(), |
741 | 0 | _ => debug_unreachable!(), |
742 | | } |
743 | 67.7M | } <smallvec::SmallVecData<[alloc::vec::Vec<u64>; 3]>>::inline_mut Line | Count | Source | 738 | 875k | unsafe fn inline_mut(&mut self) -> NonNull<A::Item> { | 739 | 875k | match self { | 740 | 875k | SmallVecData::Inline(a) => NonNull::new(a.as_mut_ptr() as *mut A::Item).unwrap(), | 741 | 0 | _ => debug_unreachable!(), | 742 | | } | 743 | 875k | } |
<smallvec::SmallVecData<[exr::meta::header::Header; 3]>>::inline_mut Line | Count | Source | 738 | 2.61M | unsafe fn inline_mut(&mut self) -> NonNull<A::Item> { | 739 | 2.61M | match self { | 740 | 2.61M | SmallVecData::Inline(a) => NonNull::new(a.as_mut_ptr() as *mut A::Item).unwrap(), | 741 | 0 | _ => debug_unreachable!(), | 742 | | } | 743 | 2.61M | } |
<smallvec::SmallVecData<[u8; 64]>>::inline_mut Line | Count | Source | 738 | 6.30M | unsafe fn inline_mut(&mut self) -> NonNull<A::Item> { | 739 | 6.30M | match self { | 740 | 6.30M | SmallVecData::Inline(a) => NonNull::new(a.as_mut_ptr() as *mut A::Item).unwrap(), | 741 | 0 | _ => debug_unreachable!(), | 742 | | } | 743 | 6.30M | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::inline_mut Unexecuted instantiation: <smallvec::SmallVecData<[exr::compression::piz::ChannelData; 6]>>::inline_mut <smallvec::SmallVecData<[exr::meta::attribute::ChannelDescription; 5]>>::inline_mut Line | Count | Source | 738 | 2.92M | unsafe fn inline_mut(&mut self) -> NonNull<A::Item> { | 739 | 2.92M | match self { | 740 | 2.92M | SmallVecData::Inline(a) => NonNull::new(a.as_mut_ptr() as *mut A::Item).unwrap(), | 741 | 0 | _ => debug_unreachable!(), | 742 | | } | 743 | 2.92M | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::block::samples::Sample; 8]>>::inline_mut <smallvec::SmallVecData<[u8; 16]>>::inline_mut Line | Count | Source | 738 | 2.91M | unsafe fn inline_mut(&mut self) -> NonNull<A::Item> { | 739 | 2.91M | match self { | 740 | 2.91M | SmallVecData::Inline(a) => NonNull::new(a.as_mut_ptr() as *mut A::Item).unwrap(), | 741 | 0 | _ => debug_unreachable!(), | 742 | | } | 743 | 2.91M | } |
<smallvec::SmallVecData<[u8; 24]>>::inline_mut Line | Count | Source | 738 | 52.0M | unsafe fn inline_mut(&mut self) -> NonNull<A::Item> { | 739 | 52.0M | match self { | 740 | 52.0M | SmallVecData::Inline(a) => NonNull::new(a.as_mut_ptr() as *mut A::Item).unwrap(), | 741 | 0 | _ => debug_unreachable!(), | 742 | | } | 743 | 52.0M | } |
<smallvec::SmallVecData<[u8; 8]>>::inline_mut Line | Count | Source | 738 | 52.8k | unsafe fn inline_mut(&mut self) -> NonNull<A::Item> { | 739 | 52.8k | match self { | 740 | 52.8k | SmallVecData::Inline(a) => NonNull::new(a.as_mut_ptr() as *mut A::Item).unwrap(), | 741 | 0 | _ => debug_unreachable!(), | 742 | | } | 743 | 52.8k | } |
Unexecuted instantiation: <smallvec::SmallVecData<[usize; 8]>>::inline_mut <smallvec::SmallVecData<[u32; 2]>>::inline_mut Line | Count | Source | 738 | 198 | unsafe fn inline_mut(&mut self) -> NonNull<A::Item> { | 739 | 198 | match self { | 740 | 198 | SmallVecData::Inline(a) => NonNull::new(a.as_mut_ptr() as *mut A::Item).unwrap(), | 741 | 0 | _ => debug_unreachable!(), | 742 | | } | 743 | 198 | } |
Unexecuted instantiation: <smallvec::SmallVecData<_>>::inline_mut |
744 | | #[inline] |
745 | 207k | fn from_inline(inline: MaybeUninit<A>) -> SmallVecData<A> { |
746 | 207k | SmallVecData::Inline(inline) |
747 | 207k | } <smallvec::SmallVecData<[u8; 24]>>::from_inline Line | Count | Source | 745 | 207k | fn from_inline(inline: MaybeUninit<A>) -> SmallVecData<A> { | 746 | 207k | SmallVecData::Inline(inline) | 747 | 207k | } |
Unexecuted instantiation: <smallvec::SmallVecData<_>>::from_inline |
748 | | // See the comment on the union variant's empty() for why this exists. |
749 | | #[inline] |
750 | 13.5M | fn empty() -> SmallVecData<A> { |
751 | | // SAFETY: MaybeUninit<A> is valid for any bit pattern including |
752 | | // uninitialized bytes, so assume_init() on a MaybeUninit of |
753 | | // that type is sound. |
754 | 13.5M | SmallVecData::Inline(unsafe { MaybeUninit::uninit().assume_init() }) |
755 | 13.5M | } <smallvec::SmallVecData<[alloc::vec::Vec<u64>; 3]>>::empty Line | Count | Source | 750 | 3.04k | fn empty() -> SmallVecData<A> { | 751 | | // SAFETY: MaybeUninit<A> is valid for any bit pattern including | 752 | | // uninitialized bytes, so assume_init() on a MaybeUninit of | 753 | | // that type is sound. | 754 | 3.04k | SmallVecData::Inline(unsafe { MaybeUninit::uninit().assume_init() }) | 755 | 3.04k | } |
<smallvec::SmallVecData<[u8; 16]>>::empty Line | Count | Source | 750 | 1.03M | fn empty() -> SmallVecData<A> { | 751 | | // SAFETY: MaybeUninit<A> is valid for any bit pattern including | 752 | | // uninitialized bytes, so assume_init() on a MaybeUninit of | 753 | | // that type is sound. | 754 | 1.03M | SmallVecData::Inline(unsafe { MaybeUninit::uninit().assume_init() }) | 755 | 1.03M | } |
<smallvec::SmallVecData<[u8; 64]>>::empty Line | Count | Source | 750 | 1.82M | fn empty() -> SmallVecData<A> { | 751 | | // SAFETY: MaybeUninit<A> is valid for any bit pattern including | 752 | | // uninitialized bytes, so assume_init() on a MaybeUninit of | 753 | | // that type is sound. | 754 | 1.82M | SmallVecData::Inline(unsafe { MaybeUninit::uninit().assume_init() }) | 755 | 1.82M | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::empty Unexecuted instantiation: <smallvec::SmallVecData<[exr::compression::piz::ChannelData; 6]>>::empty <smallvec::SmallVecData<[exr::meta::header::Header; 3]>>::empty Line | Count | Source | 750 | 875k | fn empty() -> SmallVecData<A> { | 751 | | // SAFETY: MaybeUninit<A> is valid for any bit pattern including | 752 | | // uninitialized bytes, so assume_init() on a MaybeUninit of | 753 | | // that type is sound. | 754 | 875k | SmallVecData::Inline(unsafe { MaybeUninit::uninit().assume_init() }) | 755 | 875k | } |
<smallvec::SmallVecData<[exr::meta::attribute::ChannelDescription; 5]>>::empty Line | Count | Source | 750 | 965k | fn empty() -> SmallVecData<A> { | 751 | | // SAFETY: MaybeUninit<A> is valid for any bit pattern including | 752 | | // uninitialized bytes, so assume_init() on a MaybeUninit of | 753 | | // that type is sound. | 754 | 965k | SmallVecData::Inline(unsafe { MaybeUninit::uninit().assume_init() }) | 755 | 965k | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::block::samples::Sample; 8]>>::empty <smallvec::SmallVecData<[u8; 24]>>::empty Line | Count | Source | 750 | 8.82M | fn empty() -> SmallVecData<A> { | 751 | | // SAFETY: MaybeUninit<A> is valid for any bit pattern including | 752 | | // uninitialized bytes, so assume_init() on a MaybeUninit of | 753 | | // that type is sound. | 754 | 8.82M | SmallVecData::Inline(unsafe { MaybeUninit::uninit().assume_init() }) | 755 | 8.82M | } |
<smallvec::SmallVecData<[u8; 8]>>::empty Line | Count | Source | 750 | 26.4k | fn empty() -> SmallVecData<A> { | 751 | | // SAFETY: MaybeUninit<A> is valid for any bit pattern including | 752 | | // uninitialized bytes, so assume_init() on a MaybeUninit of | 753 | | // that type is sound. | 754 | 26.4k | SmallVecData::Inline(unsafe { MaybeUninit::uninit().assume_init() }) | 755 | 26.4k | } |
Unexecuted instantiation: <smallvec::SmallVecData<[usize; 8]>>::empty <smallvec::SmallVecData<[u32; 2]>>::empty Line | Count | Source | 750 | 72 | fn empty() -> SmallVecData<A> { | 751 | | // SAFETY: MaybeUninit<A> is valid for any bit pattern including | 752 | | // uninitialized bytes, so assume_init() on a MaybeUninit of | 753 | | // that type is sound. | 754 | 72 | SmallVecData::Inline(unsafe { MaybeUninit::uninit().assume_init() }) | 755 | 72 | } |
Unexecuted instantiation: <smallvec::SmallVecData<_>>::empty |
756 | | #[inline] |
757 | 26.4k | unsafe fn into_inline(self) -> MaybeUninit<A> { |
758 | 26.4k | match self { |
759 | 26.4k | SmallVecData::Inline(a) => a, |
760 | 0 | _ => debug_unreachable!(), |
761 | | } |
762 | 26.4k | } <smallvec::SmallVecData<[u8; 8]>>::into_inline Line | Count | Source | 757 | 26.4k | unsafe fn into_inline(self) -> MaybeUninit<A> { | 758 | 26.4k | match self { | 759 | 26.4k | SmallVecData::Inline(a) => a, | 760 | 0 | _ => debug_unreachable!(), | 761 | | } | 762 | 26.4k | } |
Unexecuted instantiation: <smallvec::SmallVecData<_>>::into_inline |
763 | | #[inline] |
764 | 9.68M | unsafe fn heap(&self) -> (ConstNonNull<A::Item>, usize) { |
765 | 9.68M | match self { |
766 | 9.68M | SmallVecData::Heap { ptr, len } => (ConstNonNull(*ptr), *len), |
767 | 0 | _ => debug_unreachable!(), |
768 | | } |
769 | 9.68M | } <smallvec::SmallVecData<[u8; 64]>>::heap Line | Count | Source | 764 | 712k | unsafe fn heap(&self) -> (ConstNonNull<A::Item>, usize) { | 765 | 712k | match self { | 766 | 712k | SmallVecData::Heap { ptr, len } => (ConstNonNull(*ptr), *len), | 767 | 0 | _ => debug_unreachable!(), | 768 | | } | 769 | 712k | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::heap <smallvec::SmallVecData<[alloc::vec::Vec<u64>; 3]>>::heap Line | Count | Source | 764 | 47.2k | unsafe fn heap(&self) -> (ConstNonNull<A::Item>, usize) { | 765 | 47.2k | match self { | 766 | 47.2k | SmallVecData::Heap { ptr, len } => (ConstNonNull(*ptr), *len), | 767 | 0 | _ => debug_unreachable!(), | 768 | | } | 769 | 47.2k | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::compression::piz::ChannelData; 6]>>::heap <smallvec::SmallVecData<[exr::meta::header::Header; 3]>>::heap Line | Count | Source | 764 | 10.4k | unsafe fn heap(&self) -> (ConstNonNull<A::Item>, usize) { | 765 | 10.4k | match self { | 766 | 10.4k | SmallVecData::Heap { ptr, len } => (ConstNonNull(*ptr), *len), | 767 | 0 | _ => debug_unreachable!(), | 768 | | } | 769 | 10.4k | } |
<smallvec::SmallVecData<[exr::meta::attribute::ChannelDescription; 5]>>::heap Line | Count | Source | 764 | 11.7k | unsafe fn heap(&self) -> (ConstNonNull<A::Item>, usize) { | 765 | 11.7k | match self { | 766 | 11.7k | SmallVecData::Heap { ptr, len } => (ConstNonNull(*ptr), *len), | 767 | 0 | _ => debug_unreachable!(), | 768 | | } | 769 | 11.7k | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::block::samples::Sample; 8]>>::heap <smallvec::SmallVecData<[u8; 16]>>::heap Line | Count | Source | 764 | 45.5k | unsafe fn heap(&self) -> (ConstNonNull<A::Item>, usize) { | 765 | 45.5k | match self { | 766 | 45.5k | SmallVecData::Heap { ptr, len } => (ConstNonNull(*ptr), *len), | 767 | 0 | _ => debug_unreachable!(), | 768 | | } | 769 | 45.5k | } |
<smallvec::SmallVecData<[u8; 24]>>::heap Line | Count | Source | 764 | 8.84M | unsafe fn heap(&self) -> (ConstNonNull<A::Item>, usize) { | 765 | 8.84M | match self { | 766 | 8.84M | SmallVecData::Heap { ptr, len } => (ConstNonNull(*ptr), *len), | 767 | 0 | _ => debug_unreachable!(), | 768 | | } | 769 | 8.84M | } |
Unexecuted instantiation: <smallvec::SmallVecData<[u8; 8]>>::heap Unexecuted instantiation: <smallvec::SmallVecData<[usize; 8]>>::heap <smallvec::SmallVecData<[u32; 2]>>::heap Line | Count | Source | 764 | 11.2k | unsafe fn heap(&self) -> (ConstNonNull<A::Item>, usize) { | 765 | 11.2k | match self { | 766 | 11.2k | SmallVecData::Heap { ptr, len } => (ConstNonNull(*ptr), *len), | 767 | 0 | _ => debug_unreachable!(), | 768 | | } | 769 | 11.2k | } |
Unexecuted instantiation: <smallvec::SmallVecData<_>>::heap |
770 | | #[inline] |
771 | 9.89M | unsafe fn heap_mut(&mut self) -> (NonNull<A::Item>, &mut usize) { |
772 | 9.89M | match self { |
773 | 9.89M | SmallVecData::Heap { ptr, len } => (*ptr, len), |
774 | 0 | _ => debug_unreachable!(), |
775 | | } |
776 | 9.89M | } <smallvec::SmallVecData<[alloc::vec::Vec<u64>; 3]>>::heap_mut Line | Count | Source | 771 | 15.4k | unsafe fn heap_mut(&mut self) -> (NonNull<A::Item>, &mut usize) { | 772 | 15.4k | match self { | 773 | 15.4k | SmallVecData::Heap { ptr, len } => (*ptr, len), | 774 | 0 | _ => debug_unreachable!(), | 775 | | } | 776 | 15.4k | } |
<smallvec::SmallVecData<[exr::meta::header::Header; 3]>>::heap_mut Line | Count | Source | 771 | 38.9k | unsafe fn heap_mut(&mut self) -> (NonNull<A::Item>, &mut usize) { | 772 | 38.9k | match self { | 773 | 38.9k | SmallVecData::Heap { ptr, len } => (*ptr, len), | 774 | 0 | _ => debug_unreachable!(), | 775 | | } | 776 | 38.9k | } |
<smallvec::SmallVecData<[u8; 64]>>::heap_mut Line | Count | Source | 771 | 788k | unsafe fn heap_mut(&mut self) -> (NonNull<A::Item>, &mut usize) { | 772 | 788k | match self { | 773 | 788k | SmallVecData::Heap { ptr, len } => (*ptr, len), | 774 | 0 | _ => debug_unreachable!(), | 775 | | } | 776 | 788k | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::heap_mut Unexecuted instantiation: <smallvec::SmallVecData<[exr::compression::piz::ChannelData; 6]>>::heap_mut <smallvec::SmallVecData<[exr::meta::attribute::ChannelDescription; 5]>>::heap_mut Line | Count | Source | 771 | 15.4k | unsafe fn heap_mut(&mut self) -> (NonNull<A::Item>, &mut usize) { | 772 | 15.4k | match self { | 773 | 15.4k | SmallVecData::Heap { ptr, len } => (*ptr, len), | 774 | 0 | _ => debug_unreachable!(), | 775 | | } | 776 | 15.4k | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::block::samples::Sample; 8]>>::heap_mut <smallvec::SmallVecData<[u8; 16]>>::heap_mut Line | Count | Source | 771 | 403k | unsafe fn heap_mut(&mut self) -> (NonNull<A::Item>, &mut usize) { | 772 | 403k | match self { | 773 | 403k | SmallVecData::Heap { ptr, len } => (*ptr, len), | 774 | 0 | _ => debug_unreachable!(), | 775 | | } | 776 | 403k | } |
<smallvec::SmallVecData<[u8; 24]>>::heap_mut Line | Count | Source | 771 | 8.62M | unsafe fn heap_mut(&mut self) -> (NonNull<A::Item>, &mut usize) { | 772 | 8.62M | match self { | 773 | 8.62M | SmallVecData::Heap { ptr, len } => (*ptr, len), | 774 | 0 | _ => debug_unreachable!(), | 775 | | } | 776 | 8.62M | } |
Unexecuted instantiation: <smallvec::SmallVecData<[u8; 8]>>::heap_mut Unexecuted instantiation: <smallvec::SmallVecData<[usize; 8]>>::heap_mut <smallvec::SmallVecData<[u32; 2]>>::heap_mut Line | Count | Source | 771 | 3.72k | unsafe fn heap_mut(&mut self) -> (NonNull<A::Item>, &mut usize) { | 772 | 3.72k | match self { | 773 | 3.72k | SmallVecData::Heap { ptr, len } => (*ptr, len), | 774 | 0 | _ => debug_unreachable!(), | 775 | | } | 776 | 3.72k | } |
Unexecuted instantiation: <smallvec::SmallVecData<_>>::heap_mut |
777 | | #[inline] |
778 | 939k | fn from_heap(ptr: NonNull<A::Item>, len: usize) -> SmallVecData<A> { |
779 | 939k | SmallVecData::Heap { ptr, len } |
780 | 939k | } <smallvec::SmallVecData<[alloc::vec::Vec<u64>; 3]>>::from_heap Line | Count | Source | 778 | 1.48k | fn from_heap(ptr: NonNull<A::Item>, len: usize) -> SmallVecData<A> { | 779 | 1.48k | SmallVecData::Heap { ptr, len } | 780 | 1.48k | } |
<smallvec::SmallVecData<[exr::meta::header::Header; 3]>>::from_heap Line | Count | Source | 778 | 3.44k | fn from_heap(ptr: NonNull<A::Item>, len: usize) -> SmallVecData<A> { | 779 | 3.44k | SmallVecData::Heap { ptr, len } | 780 | 3.44k | } |
<smallvec::SmallVecData<[exr::meta::attribute::ChannelDescription; 5]>>::from_heap Line | Count | Source | 778 | 4.72k | fn from_heap(ptr: NonNull<A::Item>, len: usize) -> SmallVecData<A> { | 779 | 4.72k | SmallVecData::Heap { ptr, len } | 780 | 4.72k | } |
<smallvec::SmallVecData<[u8; 16]>>::from_heap Line | Count | Source | 778 | 201k | fn from_heap(ptr: NonNull<A::Item>, len: usize) -> SmallVecData<A> { | 779 | 201k | SmallVecData::Heap { ptr, len } | 780 | 201k | } |
<smallvec::SmallVecData<[u8; 64]>>::from_heap Line | Count | Source | 778 | 88.3k | fn from_heap(ptr: NonNull<A::Item>, len: usize) -> SmallVecData<A> { | 779 | 88.3k | SmallVecData::Heap { ptr, len } | 780 | 88.3k | } |
Unexecuted instantiation: <smallvec::SmallVecData<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::from_heap Unexecuted instantiation: <smallvec::SmallVecData<[exr::compression::piz::ChannelData; 6]>>::from_heap Unexecuted instantiation: <smallvec::SmallVecData<[exr::block::samples::Sample; 8]>>::from_heap <smallvec::SmallVecData<[u8; 24]>>::from_heap Line | Count | Source | 778 | 639k | fn from_heap(ptr: NonNull<A::Item>, len: usize) -> SmallVecData<A> { | 779 | 639k | SmallVecData::Heap { ptr, len } | 780 | 639k | } |
Unexecuted instantiation: <smallvec::SmallVecData<[u8; 8]>>::from_heap Unexecuted instantiation: <smallvec::SmallVecData<[usize; 8]>>::from_heap <smallvec::SmallVecData<[u32; 2]>>::from_heap Line | Count | Source | 778 | 149 | fn from_heap(ptr: NonNull<A::Item>, len: usize) -> SmallVecData<A> { | 779 | 149 | SmallVecData::Heap { ptr, len } | 780 | 149 | } |
Unexecuted instantiation: <smallvec::SmallVecData<_>>::from_heap |
781 | | } |
782 | | |
783 | | unsafe impl<A: Array + Send> Send for SmallVecData<A> {} |
784 | | unsafe impl<A: Array + Sync> Sync for SmallVecData<A> {} |
785 | | |
786 | | /// A `Vec`-like container that can store a small number of elements inline. |
787 | | /// |
788 | | /// `SmallVec` acts like a vector, but can store a limited amount of data inline |
789 | | /// within the `SmallVec` struct rather than in a separate allocation. If the |
790 | | /// data exceeds this limit, the `SmallVec` will "spill" its data onto the heap, |
791 | | /// allocating a new buffer to hold it. |
792 | | /// |
793 | | /// The amount of data that a `SmallVec` can store inline depends on its backing |
794 | | /// store. The backing store can be any type that implements the `Array` trait; |
795 | | /// usually it is a small fixed-sized array. For example a `SmallVec<[u64; 8]>` |
796 | | /// can hold up to eight 64-bit integers inline. |
797 | | /// |
798 | | /// ## Example |
799 | | /// |
800 | | /// ```rust |
801 | | /// use smallvec::SmallVec; |
802 | | /// let mut v = SmallVec::<[u8; 4]>::new(); // initialize an empty vector |
803 | | /// |
804 | | /// // The vector can hold up to 4 items without spilling onto the heap. |
805 | | /// v.extend(0..4); |
806 | | /// assert_eq!(v.len(), 4); |
807 | | /// assert!(!v.spilled()); |
808 | | /// |
809 | | /// // Pushing another element will force the buffer to spill: |
810 | | /// v.push(4); |
811 | | /// assert_eq!(v.len(), 5); |
812 | | /// assert!(v.spilled()); |
813 | | /// ``` |
814 | | /// |
815 | | /// References used by an element's destructor must outlive the vector, even |
816 | | /// with the `may_dangle` feature and no inline storage: |
817 | | /// |
818 | | /// ```compile_fail,E0597 |
819 | | /// use smallvec::SmallVec; |
820 | | /// |
821 | | /// struct PrintOnDrop<'a>(&'a str); |
822 | | /// impl Drop for PrintOnDrop<'_> { |
823 | | /// fn drop(&mut self) { |
824 | | /// println!("{}", self.0); |
825 | | /// } |
826 | | /// } |
827 | | /// |
828 | | /// let mut v = SmallVec::<[PrintOnDrop<'_>; 0]>::new(); |
829 | | /// let text = String::from("borrowed"); |
830 | | /// v.push(PrintOnDrop(&text)); |
831 | | /// // `text` is dropped before `v`, whose elements still need it. |
832 | | /// ``` |
833 | | pub struct SmallVec<A: Array> { |
834 | | // The capacity field is used to determine which of the storage variants is active: |
835 | | // If capacity <= Self::inline_capacity() then the inline variant is used and capacity holds |
836 | | // the current length of the vector (number of elements actually in use). If capacity > |
837 | | // Self::inline_capacity() then the heap variant is used and capacity holds the size of the |
838 | | // memory allocation. |
839 | | capacity: usize, |
840 | | data: SmallVecData<A>, |
841 | | // Own A::Item, including when A has length zero and all items are on the heap. |
842 | | // This is required for sound drop checking with #[may_dangle]. |
843 | | _marker: PhantomData<A::Item>, |
844 | | } |
845 | | |
846 | | impl<A: Array> SmallVec<A> { |
847 | | /// Construct an empty vector |
848 | | #[inline] |
849 | 13.5M | pub fn new() -> SmallVec<A> { |
850 | | // Try to detect invalid custom implementations of `Array`. Hopefully, |
851 | | // this check should be optimized away entirely for valid ones. |
852 | 13.5M | assert!( |
853 | 13.5M | mem::size_of::<A>() == A::size() * mem::size_of::<A::Item>() |
854 | 13.5M | && mem::align_of::<A>() >= mem::align_of::<A::Item>() |
855 | | ); |
856 | 13.5M | SmallVec { |
857 | 13.5M | capacity: 0, |
858 | 13.5M | data: SmallVecData::empty(), |
859 | 13.5M | _marker: PhantomData, |
860 | 13.5M | } |
861 | 13.5M | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::new Line | Count | Source | 849 | 3.04k | pub fn new() -> SmallVec<A> { | 850 | | // Try to detect invalid custom implementations of `Array`. Hopefully, | 851 | | // this check should be optimized away entirely for valid ones. | 852 | 3.04k | assert!( | 853 | 3.04k | mem::size_of::<A>() == A::size() * mem::size_of::<A::Item>() | 854 | 3.04k | && mem::align_of::<A>() >= mem::align_of::<A::Item>() | 855 | | ); | 856 | 3.04k | SmallVec { | 857 | 3.04k | capacity: 0, | 858 | 3.04k | data: SmallVecData::empty(), | 859 | 3.04k | _marker: PhantomData, | 860 | 3.04k | } | 861 | 3.04k | } |
<smallvec::SmallVec<[u8; 16]>>::new Line | Count | Source | 849 | 1.03M | pub fn new() -> SmallVec<A> { | 850 | | // Try to detect invalid custom implementations of `Array`. Hopefully, | 851 | | // this check should be optimized away entirely for valid ones. | 852 | 1.03M | assert!( | 853 | 1.03M | mem::size_of::<A>() == A::size() * mem::size_of::<A::Item>() | 854 | 1.03M | && mem::align_of::<A>() >= mem::align_of::<A::Item>() | 855 | | ); | 856 | 1.03M | SmallVec { | 857 | 1.03M | capacity: 0, | 858 | 1.03M | data: SmallVecData::empty(), | 859 | 1.03M | _marker: PhantomData, | 860 | 1.03M | } | 861 | 1.03M | } |
<smallvec::SmallVec<[u8; 64]>>::new Line | Count | Source | 849 | 1.82M | pub fn new() -> SmallVec<A> { | 850 | | // Try to detect invalid custom implementations of `Array`. Hopefully, | 851 | | // this check should be optimized away entirely for valid ones. | 852 | 1.82M | assert!( | 853 | 1.82M | mem::size_of::<A>() == A::size() * mem::size_of::<A::Item>() | 854 | 1.82M | && mem::align_of::<A>() >= mem::align_of::<A::Item>() | 855 | | ); | 856 | 1.82M | SmallVec { | 857 | 1.82M | capacity: 0, | 858 | 1.82M | data: SmallVecData::empty(), | 859 | 1.82M | _marker: PhantomData, | 860 | 1.82M | } | 861 | 1.82M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::new Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::new <smallvec::SmallVec<[exr::meta::header::Header; 3]>>::new Line | Count | Source | 849 | 875k | pub fn new() -> SmallVec<A> { | 850 | | // Try to detect invalid custom implementations of `Array`. Hopefully, | 851 | | // this check should be optimized away entirely for valid ones. | 852 | 875k | assert!( | 853 | 875k | mem::size_of::<A>() == A::size() * mem::size_of::<A::Item>() | 854 | 875k | && mem::align_of::<A>() >= mem::align_of::<A::Item>() | 855 | | ); | 856 | 875k | SmallVec { | 857 | 875k | capacity: 0, | 858 | 875k | data: SmallVecData::empty(), | 859 | 875k | _marker: PhantomData, | 860 | 875k | } | 861 | 875k | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]>>::new Line | Count | Source | 849 | 965k | pub fn new() -> SmallVec<A> { | 850 | | // Try to detect invalid custom implementations of `Array`. Hopefully, | 851 | | // this check should be optimized away entirely for valid ones. | 852 | 965k | assert!( | 853 | 965k | mem::size_of::<A>() == A::size() * mem::size_of::<A::Item>() | 854 | 965k | && mem::align_of::<A>() >= mem::align_of::<A::Item>() | 855 | | ); | 856 | 965k | SmallVec { | 857 | 965k | capacity: 0, | 858 | 965k | data: SmallVecData::empty(), | 859 | 965k | _marker: PhantomData, | 860 | 965k | } | 861 | 965k | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]>>::new <smallvec::SmallVec<[u8; 24]>>::new Line | Count | Source | 849 | 8.79M | pub fn new() -> SmallVec<A> { | 850 | | // Try to detect invalid custom implementations of `Array`. Hopefully, | 851 | | // this check should be optimized away entirely for valid ones. | 852 | 8.79M | assert!( | 853 | 8.79M | mem::size_of::<A>() == A::size() * mem::size_of::<A::Item>() | 854 | 8.79M | && mem::align_of::<A>() >= mem::align_of::<A::Item>() | 855 | | ); | 856 | 8.79M | SmallVec { | 857 | 8.79M | capacity: 0, | 858 | 8.79M | data: SmallVecData::empty(), | 859 | 8.79M | _marker: PhantomData, | 860 | 8.79M | } | 861 | 8.79M | } |
<smallvec::SmallVec<[u8; 8]>>::new Line | Count | Source | 849 | 26.4k | pub fn new() -> SmallVec<A> { | 850 | | // Try to detect invalid custom implementations of `Array`. Hopefully, | 851 | | // this check should be optimized away entirely for valid ones. | 852 | 26.4k | assert!( | 853 | 26.4k | mem::size_of::<A>() == A::size() * mem::size_of::<A::Item>() | 854 | 26.4k | && mem::align_of::<A>() >= mem::align_of::<A::Item>() | 855 | | ); | 856 | 26.4k | SmallVec { | 857 | 26.4k | capacity: 0, | 858 | 26.4k | data: SmallVecData::empty(), | 859 | 26.4k | _marker: PhantomData, | 860 | 26.4k | } | 861 | 26.4k | } |
Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]>>::new <smallvec::SmallVec<[u32; 2]>>::new Line | Count | Source | 849 | 72 | pub fn new() -> SmallVec<A> { | 850 | | // Try to detect invalid custom implementations of `Array`. Hopefully, | 851 | | // this check should be optimized away entirely for valid ones. | 852 | 72 | assert!( | 853 | 72 | mem::size_of::<A>() == A::size() * mem::size_of::<A::Item>() | 854 | 72 | && mem::align_of::<A>() >= mem::align_of::<A::Item>() | 855 | | ); | 856 | 72 | SmallVec { | 857 | 72 | capacity: 0, | 858 | 72 | data: SmallVecData::empty(), | 859 | 72 | _marker: PhantomData, | 860 | 72 | } | 861 | 72 | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::new |
862 | | |
863 | | /// Construct an empty vector with enough capacity pre-allocated to store at |
864 | | /// least `n` elements. |
865 | | /// |
866 | | /// Will create a heap allocation only if `n` is larger than the inline |
867 | | /// capacity. |
868 | | /// |
869 | | /// ``` |
870 | | /// # use smallvec::SmallVec; |
871 | | /// |
872 | | /// let v: SmallVec<[u8; 3]> = SmallVec::with_capacity(100); |
873 | | /// |
874 | | /// assert!(v.is_empty()); |
875 | | /// assert!(v.capacity() >= 100); |
876 | | /// ``` |
877 | | #[inline] |
878 | 0 | pub fn with_capacity(n: usize) -> Self { |
879 | 0 | let mut v = SmallVec::new(); |
880 | 0 | v.reserve_exact(n); |
881 | 0 | v |
882 | 0 | } |
883 | | |
884 | | /// Construct a new `SmallVec` from a `Vec<A::Item>`. |
885 | | /// |
886 | | /// Elements will be copied to the inline buffer if `vec.capacity() <= |
887 | | /// Self::inline_capacity()`. |
888 | | /// |
889 | | /// ```rust |
890 | | /// use smallvec::SmallVec; |
891 | | /// |
892 | | /// let vec = vec![1, 2, 3, 4, 5]; |
893 | | /// let small_vec: SmallVec<[_; 3]> = SmallVec::from_vec(vec); |
894 | | /// |
895 | | /// assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]); |
896 | | /// ``` |
897 | | #[inline] |
898 | 51.7k | pub fn from_vec(mut vec: Vec<A::Item>) -> SmallVec<A> { |
899 | 51.7k | if vec.capacity() <= Self::inline_capacity() { |
900 | | // Cannot use Vec with smaller capacity |
901 | | // because we use value of `Self::capacity` field as indicator. |
902 | | unsafe { |
903 | 25.9k | let mut data = SmallVecData::<A>::empty(); |
904 | 25.9k | let len = vec.len(); |
905 | 25.9k | vec.set_len(0); |
906 | 25.9k | ptr::copy_nonoverlapping(vec.as_ptr(), data.inline_mut().as_ptr(), len); |
907 | | |
908 | 25.9k | SmallVec { |
909 | 25.9k | capacity: len, |
910 | 25.9k | data, |
911 | 25.9k | _marker: PhantomData, |
912 | 25.9k | } |
913 | | } |
914 | | } else { |
915 | 25.8k | let (ptr, cap, len) = (vec.as_mut_ptr(), vec.capacity(), vec.len()); |
916 | 25.8k | mem::forget(vec); |
917 | 25.8k | let ptr = NonNull::new(ptr) |
918 | | // See docs: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.as_mut_ptr |
919 | 25.8k | .expect("Cannot be null by `Vec` invariant"); |
920 | | |
921 | 25.8k | SmallVec { |
922 | 25.8k | capacity: cap, |
923 | 25.8k | data: SmallVecData::from_heap(ptr, len), |
924 | 25.8k | _marker: PhantomData, |
925 | 25.8k | } |
926 | | } |
927 | 51.7k | } Unexecuted instantiation: <smallvec::SmallVec<[exr::meta::header::Header; 3]>>::from_vec <smallvec::SmallVec<[u8; 24]>>::from_vec Line | Count | Source | 898 | 51.7k | pub fn from_vec(mut vec: Vec<A::Item>) -> SmallVec<A> { | 899 | 51.7k | if vec.capacity() <= Self::inline_capacity() { | 900 | | // Cannot use Vec with smaller capacity | 901 | | // because we use value of `Self::capacity` field as indicator. | 902 | | unsafe { | 903 | 25.9k | let mut data = SmallVecData::<A>::empty(); | 904 | 25.9k | let len = vec.len(); | 905 | 25.9k | vec.set_len(0); | 906 | 25.9k | ptr::copy_nonoverlapping(vec.as_ptr(), data.inline_mut().as_ptr(), len); | 907 | | | 908 | 25.9k | SmallVec { | 909 | 25.9k | capacity: len, | 910 | 25.9k | data, | 911 | 25.9k | _marker: PhantomData, | 912 | 25.9k | } | 913 | | } | 914 | | } else { | 915 | 25.8k | let (ptr, cap, len) = (vec.as_mut_ptr(), vec.capacity(), vec.len()); | 916 | 25.8k | mem::forget(vec); | 917 | 25.8k | let ptr = NonNull::new(ptr) | 918 | | // See docs: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.as_mut_ptr | 919 | 25.8k | .expect("Cannot be null by `Vec` invariant"); | 920 | | | 921 | 25.8k | SmallVec { | 922 | 25.8k | capacity: cap, | 923 | 25.8k | data: SmallVecData::from_heap(ptr, len), | 924 | 25.8k | _marker: PhantomData, | 925 | 25.8k | } | 926 | | } | 927 | 51.7k | } |
Unexecuted instantiation: <smallvec::SmallVec<[u32; 2]>>::from_vec Unexecuted instantiation: <smallvec::SmallVec<_>>::from_vec |
928 | | |
929 | | /// Constructs a new `SmallVec` on the stack from an `A` without |
930 | | /// copying elements. |
931 | | /// |
932 | | /// ```rust |
933 | | /// use smallvec::SmallVec; |
934 | | /// |
935 | | /// let buf = [1, 2, 3, 4, 5]; |
936 | | /// let small_vec: SmallVec<_> = SmallVec::from_buf(buf); |
937 | | /// |
938 | | /// assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]); |
939 | | /// ``` |
940 | | #[inline] |
941 | 0 | pub fn from_buf(buf: A) -> SmallVec<A> { |
942 | 0 | SmallVec { |
943 | 0 | capacity: A::size(), |
944 | 0 | data: SmallVecData::from_inline(MaybeUninit::new(buf)), |
945 | 0 | _marker: PhantomData, |
946 | 0 | } |
947 | 0 | } |
948 | | |
949 | | /// Constructs a new `SmallVec` on the stack from an `A` without |
950 | | /// copying elements. Also sets the length, which must be less or |
951 | | /// equal to the size of `buf`. |
952 | | /// |
953 | | /// ```rust |
954 | | /// use smallvec::SmallVec; |
955 | | /// |
956 | | /// let buf = [1, 2, 3, 4, 5, 0, 0, 0]; |
957 | | /// let small_vec: SmallVec<_> = SmallVec::from_buf_and_len(buf, 5); |
958 | | /// |
959 | | /// assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]); |
960 | | /// ``` |
961 | | #[inline] |
962 | 0 | pub fn from_buf_and_len(buf: A, len: usize) -> SmallVec<A> { |
963 | 0 | assert!(len <= A::size()); |
964 | 0 | unsafe { SmallVec::from_buf_and_len_unchecked(MaybeUninit::new(buf), len) } |
965 | 0 | } |
966 | | |
967 | | /// Constructs a new `SmallVec` on the stack from an `A` without |
968 | | /// copying elements. Also sets the length. The user is responsible |
969 | | /// for ensuring that `len <= A::size()`. |
970 | | /// |
971 | | /// ```rust |
972 | | /// use {smallvec::SmallVec, std::mem::MaybeUninit}; |
973 | | /// |
974 | | /// let buf = [1, 2, 3, 4, 5, 0, 0, 0]; |
975 | | /// let small_vec: SmallVec<_> = |
976 | | /// unsafe { SmallVec::from_buf_and_len_unchecked(MaybeUninit::new(buf), 5) }; |
977 | | /// |
978 | | /// assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]); |
979 | | /// ``` |
980 | | #[inline] |
981 | 0 | pub unsafe fn from_buf_and_len_unchecked(buf: MaybeUninit<A>, len: usize) -> SmallVec<A> { |
982 | 0 | SmallVec { |
983 | 0 | capacity: len, |
984 | 0 | data: SmallVecData::from_inline(buf), |
985 | 0 | _marker: PhantomData, |
986 | 0 | } |
987 | 0 | } |
988 | | |
989 | | /// Sets the length of a vector. |
990 | | /// |
991 | | /// This will explicitly set the size of the vector, without actually |
992 | | /// modifying its buffers, so it is up to the caller to ensure that the |
993 | | /// vector is actually the specified size. |
994 | 95 | pub unsafe fn set_len(&mut self, new_len: usize) { |
995 | 95 | let (_, len_ptr, _) = self.triple_mut(); |
996 | 95 | *len_ptr = new_len; |
997 | 95 | } Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::set_len Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::set_len Unexecuted instantiation: <smallvec::SmallVec<_>>::set_len Unexecuted instantiation: <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::set_len <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::set_len Line | Count | Source | 994 | 95 | pub unsafe fn set_len(&mut self, new_len: usize) { | 995 | 95 | let (_, len_ptr, _) = self.triple_mut(); | 996 | 95 | *len_ptr = new_len; | 997 | 95 | } |
|
998 | | |
999 | | /// The maximum number of elements this vector can hold inline |
1000 | | #[inline] |
1001 | 296M | fn inline_capacity() -> usize { |
1002 | 296M | if mem::size_of::<A::Item>() > 0 { |
1003 | 296M | A::size() |
1004 | | } else { |
1005 | | // For zero-size items code like `ptr.add(offset)` always returns |
1006 | | // the same pointer. Therefore all items are at the same |
1007 | | // address, and any array size has capacity for |
1008 | | // infinitely many items. The capacity is limited by the |
1009 | | // bit width of the length field. |
1010 | | // |
1011 | | // `Vec` also does this: |
1012 | | // https://github.com/rust-lang/rust/blob/1.44.0/src/liballoc/raw_vec.rs#L186 |
1013 | | // |
1014 | | // In our case, this also ensures that a smallvec of zero-size items |
1015 | | // never spills, and we never try to allocate zero bytes |
1016 | | // which `std::alloc::alloc` disallows. |
1017 | | #[allow(deprecated)] |
1018 | 0 | core::usize::MAX |
1019 | | } |
1020 | 296M | } <smallvec::SmallVec<[u8; 64]>>::inline_capacity Line | Count | Source | 1001 | 36.2M | fn inline_capacity() -> usize { | 1002 | 36.2M | if mem::size_of::<A::Item>() > 0 { | 1003 | 36.2M | A::size() | 1004 | | } else { | 1005 | | // For zero-size items code like `ptr.add(offset)` always returns | 1006 | | // the same pointer. Therefore all items are at the same | 1007 | | // address, and any array size has capacity for | 1008 | | // infinitely many items. The capacity is limited by the | 1009 | | // bit width of the length field. | 1010 | | // | 1011 | | // `Vec` also does this: | 1012 | | // https://github.com/rust-lang/rust/blob/1.44.0/src/liballoc/raw_vec.rs#L186 | 1013 | | // | 1014 | | // In our case, this also ensures that a smallvec of zero-size items | 1015 | | // never spills, and we never try to allocate zero bytes | 1016 | | // which `std::alloc::alloc` disallows. | 1017 | | #[allow(deprecated)] | 1018 | 0 | core::usize::MAX | 1019 | | } | 1020 | 36.2M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::inline_capacity <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::inline_capacity Line | Count | Source | 1001 | 5.08M | fn inline_capacity() -> usize { | 1002 | 5.08M | if mem::size_of::<A::Item>() > 0 { | 1003 | 5.08M | A::size() | 1004 | | } else { | 1005 | | // For zero-size items code like `ptr.add(offset)` always returns | 1006 | | // the same pointer. Therefore all items are at the same | 1007 | | // address, and any array size has capacity for | 1008 | | // infinitely many items. The capacity is limited by the | 1009 | | // bit width of the length field. | 1010 | | // | 1011 | | // `Vec` also does this: | 1012 | | // https://github.com/rust-lang/rust/blob/1.44.0/src/liballoc/raw_vec.rs#L186 | 1013 | | // | 1014 | | // In our case, this also ensures that a smallvec of zero-size items | 1015 | | // never spills, and we never try to allocate zero bytes | 1016 | | // which `std::alloc::alloc` disallows. | 1017 | | #[allow(deprecated)] | 1018 | 0 | core::usize::MAX | 1019 | | } | 1020 | 5.08M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::inline_capacity <smallvec::SmallVec<[exr::meta::header::Header; 3]>>::inline_capacity Line | Count | Source | 1001 | 18.4M | fn inline_capacity() -> usize { | 1002 | 18.4M | if mem::size_of::<A::Item>() > 0 { | 1003 | 18.4M | A::size() | 1004 | | } else { | 1005 | | // For zero-size items code like `ptr.add(offset)` always returns | 1006 | | // the same pointer. Therefore all items are at the same | 1007 | | // address, and any array size has capacity for | 1008 | | // infinitely many items. The capacity is limited by the | 1009 | | // bit width of the length field. | 1010 | | // | 1011 | | // `Vec` also does this: | 1012 | | // https://github.com/rust-lang/rust/blob/1.44.0/src/liballoc/raw_vec.rs#L186 | 1013 | | // | 1014 | | // In our case, this also ensures that a smallvec of zero-size items | 1015 | | // never spills, and we never try to allocate zero bytes | 1016 | | // which `std::alloc::alloc` disallows. | 1017 | | #[allow(deprecated)] | 1018 | 0 | core::usize::MAX | 1019 | | } | 1020 | 18.4M | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]>>::inline_capacity Line | Count | Source | 1001 | 9.24M | fn inline_capacity() -> usize { | 1002 | 9.24M | if mem::size_of::<A::Item>() > 0 { | 1003 | 9.24M | A::size() | 1004 | | } else { | 1005 | | // For zero-size items code like `ptr.add(offset)` always returns | 1006 | | // the same pointer. Therefore all items are at the same | 1007 | | // address, and any array size has capacity for | 1008 | | // infinitely many items. The capacity is limited by the | 1009 | | // bit width of the length field. | 1010 | | // | 1011 | | // `Vec` also does this: | 1012 | | // https://github.com/rust-lang/rust/blob/1.44.0/src/liballoc/raw_vec.rs#L186 | 1013 | | // | 1014 | | // In our case, this also ensures that a smallvec of zero-size items | 1015 | | // never spills, and we never try to allocate zero bytes | 1016 | | // which `std::alloc::alloc` disallows. | 1017 | | #[allow(deprecated)] | 1018 | 0 | core::usize::MAX | 1019 | | } | 1020 | 9.24M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]>>::inline_capacity <smallvec::SmallVec<[u8; 16]>>::inline_capacity Line | Count | Source | 1001 | 7.78M | fn inline_capacity() -> usize { | 1002 | 7.78M | if mem::size_of::<A::Item>() > 0 { | 1003 | 7.78M | A::size() | 1004 | | } else { | 1005 | | // For zero-size items code like `ptr.add(offset)` always returns | 1006 | | // the same pointer. Therefore all items are at the same | 1007 | | // address, and any array size has capacity for | 1008 | | // infinitely many items. The capacity is limited by the | 1009 | | // bit width of the length field. | 1010 | | // | 1011 | | // `Vec` also does this: | 1012 | | // https://github.com/rust-lang/rust/blob/1.44.0/src/liballoc/raw_vec.rs#L186 | 1013 | | // | 1014 | | // In our case, this also ensures that a smallvec of zero-size items | 1015 | | // never spills, and we never try to allocate zero bytes | 1016 | | // which `std::alloc::alloc` disallows. | 1017 | | #[allow(deprecated)] | 1018 | 0 | core::usize::MAX | 1019 | | } | 1020 | 7.78M | } |
<smallvec::SmallVec<[u8; 24]>>::inline_capacity Line | Count | Source | 1001 | 219M | fn inline_capacity() -> usize { | 1002 | 219M | if mem::size_of::<A::Item>() > 0 { | 1003 | 219M | A::size() | 1004 | | } else { | 1005 | | // For zero-size items code like `ptr.add(offset)` always returns | 1006 | | // the same pointer. Therefore all items are at the same | 1007 | | // address, and any array size has capacity for | 1008 | | // infinitely many items. The capacity is limited by the | 1009 | | // bit width of the length field. | 1010 | | // | 1011 | | // `Vec` also does this: | 1012 | | // https://github.com/rust-lang/rust/blob/1.44.0/src/liballoc/raw_vec.rs#L186 | 1013 | | // | 1014 | | // In our case, this also ensures that a smallvec of zero-size items | 1015 | | // never spills, and we never try to allocate zero bytes | 1016 | | // which `std::alloc::alloc` disallows. | 1017 | | #[allow(deprecated)] | 1018 | 0 | core::usize::MAX | 1019 | | } | 1020 | 219M | } |
<smallvec::SmallVec<[u8; 8]>>::inline_capacity Line | Count | Source | 1001 | 184k | fn inline_capacity() -> usize { | 1002 | 184k | if mem::size_of::<A::Item>() > 0 { | 1003 | 184k | A::size() | 1004 | | } else { | 1005 | | // For zero-size items code like `ptr.add(offset)` always returns | 1006 | | // the same pointer. Therefore all items are at the same | 1007 | | // address, and any array size has capacity for | 1008 | | // infinitely many items. The capacity is limited by the | 1009 | | // bit width of the length field. | 1010 | | // | 1011 | | // `Vec` also does this: | 1012 | | // https://github.com/rust-lang/rust/blob/1.44.0/src/liballoc/raw_vec.rs#L186 | 1013 | | // | 1014 | | // In our case, this also ensures that a smallvec of zero-size items | 1015 | | // never spills, and we never try to allocate zero bytes | 1016 | | // which `std::alloc::alloc` disallows. | 1017 | | #[allow(deprecated)] | 1018 | 0 | core::usize::MAX | 1019 | | } | 1020 | 184k | } |
Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]>>::inline_capacity <smallvec::SmallVec<[u32; 2]>>::inline_capacity Line | Count | Source | 1001 | 17.7k | fn inline_capacity() -> usize { | 1002 | 17.7k | if mem::size_of::<A::Item>() > 0 { | 1003 | 17.7k | A::size() | 1004 | | } else { | 1005 | | // For zero-size items code like `ptr.add(offset)` always returns | 1006 | | // the same pointer. Therefore all items are at the same | 1007 | | // address, and any array size has capacity for | 1008 | | // infinitely many items. The capacity is limited by the | 1009 | | // bit width of the length field. | 1010 | | // | 1011 | | // `Vec` also does this: | 1012 | | // https://github.com/rust-lang/rust/blob/1.44.0/src/liballoc/raw_vec.rs#L186 | 1013 | | // | 1014 | | // In our case, this also ensures that a smallvec of zero-size items | 1015 | | // never spills, and we never try to allocate zero bytes | 1016 | | // which `std::alloc::alloc` disallows. | 1017 | | #[allow(deprecated)] | 1018 | 0 | core::usize::MAX | 1019 | | } | 1020 | 17.7k | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::inline_capacity |
1021 | | |
1022 | | /// The maximum number of elements this vector can hold inline |
1023 | | #[inline] |
1024 | 3.86M | pub fn inline_size(&self) -> usize { |
1025 | 3.86M | Self::inline_capacity() |
1026 | 3.86M | } <smallvec::SmallVec<[exr::meta::header::Header; 3]>>::inline_size Line | Count | Source | 1024 | 5.17k | pub fn inline_size(&self) -> usize { | 1025 | 5.17k | Self::inline_capacity() | 1026 | 5.17k | } |
<smallvec::SmallVec<[u8; 24]>>::inline_size Line | Count | Source | 1024 | 3.85M | pub fn inline_size(&self) -> usize { | 1025 | 3.85M | Self::inline_capacity() | 1026 | 3.85M | } |
<smallvec::SmallVec<[u32; 2]>>::inline_size Line | Count | Source | 1024 | 72 | pub fn inline_size(&self) -> usize { | 1025 | 72 | Self::inline_capacity() | 1026 | 72 | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::inline_size |
1027 | | |
1028 | | /// The number of elements stored in the vector |
1029 | | #[inline] |
1030 | 47.0M | pub fn len(&self) -> usize { |
1031 | 47.0M | self.triple().1 |
1032 | 47.0M | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::len Line | Count | Source | 1030 | 1.57k | pub fn len(&self) -> usize { | 1031 | 1.57k | self.triple().1 | 1032 | 1.57k | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]>>::len Line | Count | Source | 1030 | 884k | pub fn len(&self) -> usize { | 1031 | 884k | self.triple().1 | 1032 | 884k | } |
<smallvec::SmallVec<[u8; 64]>>::len Line | Count | Source | 1030 | 8.83M | pub fn len(&self) -> usize { | 1031 | 8.83M | self.triple().1 | 1032 | 8.83M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::len Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::len <smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]>>::len Line | Count | Source | 1030 | 4.86k | pub fn len(&self) -> usize { | 1031 | 4.86k | self.triple().1 | 1032 | 4.86k | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]>>::len Unexecuted instantiation: <smallvec::SmallVec<[u8; 16]>>::len <smallvec::SmallVec<[u8; 24]>>::len Line | Count | Source | 1030 | 37.3M | pub fn len(&self) -> usize { | 1031 | 37.3M | self.triple().1 | 1032 | 37.3M | } |
<smallvec::SmallVec<[u8; 8]>>::len Line | Count | Source | 1030 | 26.4k | pub fn len(&self) -> usize { | 1031 | 26.4k | self.triple().1 | 1032 | 26.4k | } |
Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]>>::len <smallvec::SmallVec<[u32; 2]>>::len Line | Count | Source | 1030 | 149 | pub fn len(&self) -> usize { | 1031 | 149 | self.triple().1 | 1032 | 149 | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::len |
1033 | | |
1034 | | /// Returns `true` if the vector is empty |
1035 | | #[inline] |
1036 | 0 | pub fn is_empty(&self) -> bool { |
1037 | 0 | self.len() == 0 |
1038 | 0 | } |
1039 | | |
1040 | | /// The number of items the vector can hold without reallocating |
1041 | | #[inline] |
1042 | 0 | pub fn capacity(&self) -> usize { |
1043 | 0 | self.triple().2 |
1044 | 0 | } |
1045 | | |
1046 | | /// Returns a tuple with (data ptr, len, capacity) |
1047 | | /// Useful to get all `SmallVec` properties with a single check of the |
1048 | | /// current storage variant. |
1049 | | #[inline] |
1050 | 70.8M | fn triple(&self) -> (ConstNonNull<A::Item>, usize, usize) { |
1051 | | unsafe { |
1052 | 70.8M | if self.spilled() { |
1053 | 9.68M | let (ptr, len) = self.data.heap(); |
1054 | 9.68M | (ptr, len, self.capacity) |
1055 | | } else { |
1056 | 61.1M | (self.data.inline(), self.capacity, Self::inline_capacity()) |
1057 | | } |
1058 | | } |
1059 | 70.8M | } <smallvec::SmallVec<[u8; 64]>>::triple Line | Count | Source | 1050 | 10.7M | fn triple(&self) -> (ConstNonNull<A::Item>, usize, usize) { | 1051 | | unsafe { | 1052 | 10.7M | if self.spilled() { | 1053 | 712k | let (ptr, len) = self.data.heap(); | 1054 | 712k | (ptr, len, self.capacity) | 1055 | | } else { | 1056 | 10.0M | (self.data.inline(), self.capacity, Self::inline_capacity()) | 1057 | | } | 1058 | | } | 1059 | 10.7M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::triple <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::triple Line | Count | Source | 1050 | 1.67M | fn triple(&self) -> (ConstNonNull<A::Item>, usize, usize) { | 1051 | | unsafe { | 1052 | 1.67M | if self.spilled() { | 1053 | 47.2k | let (ptr, len) = self.data.heap(); | 1054 | 47.2k | (ptr, len, self.capacity) | 1055 | | } else { | 1056 | 1.63M | (self.data.inline(), self.capacity, Self::inline_capacity()) | 1057 | | } | 1058 | | } | 1059 | 1.67M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::triple <smallvec::SmallVec<[exr::meta::header::Header; 3]>>::triple Line | Count | Source | 1050 | 6.15M | fn triple(&self) -> (ConstNonNull<A::Item>, usize, usize) { | 1051 | | unsafe { | 1052 | 6.15M | if self.spilled() { | 1053 | 10.4k | let (ptr, len) = self.data.heap(); | 1054 | 10.4k | (ptr, len, self.capacity) | 1055 | | } else { | 1056 | 6.14M | (self.data.inline(), self.capacity, Self::inline_capacity()) | 1057 | | } | 1058 | | } | 1059 | 6.15M | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]>>::triple Line | Count | Source | 1050 | 1.21M | fn triple(&self) -> (ConstNonNull<A::Item>, usize, usize) { | 1051 | | unsafe { | 1052 | 1.21M | if self.spilled() { | 1053 | 11.7k | let (ptr, len) = self.data.heap(); | 1054 | 11.7k | (ptr, len, self.capacity) | 1055 | | } else { | 1056 | 1.20M | (self.data.inline(), self.capacity, Self::inline_capacity()) | 1057 | | } | 1058 | | } | 1059 | 1.21M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]>>::triple <smallvec::SmallVec<[u8; 16]>>::triple Line | Count | Source | 1050 | 177k | fn triple(&self) -> (ConstNonNull<A::Item>, usize, usize) { | 1051 | | unsafe { | 1052 | 177k | if self.spilled() { | 1053 | 45.5k | let (ptr, len) = self.data.heap(); | 1054 | 45.5k | (ptr, len, self.capacity) | 1055 | | } else { | 1056 | 132k | (self.data.inline(), self.capacity, Self::inline_capacity()) | 1057 | | } | 1058 | | } | 1059 | 177k | } |
<smallvec::SmallVec<[u8; 24]>>::triple Line | Count | Source | 1050 | 50.8M | fn triple(&self) -> (ConstNonNull<A::Item>, usize, usize) { | 1051 | | unsafe { | 1052 | 50.8M | if self.spilled() { | 1053 | 8.84M | let (ptr, len) = self.data.heap(); | 1054 | 8.84M | (ptr, len, self.capacity) | 1055 | | } else { | 1056 | 41.9M | (self.data.inline(), self.capacity, Self::inline_capacity()) | 1057 | | } | 1058 | | } | 1059 | 50.8M | } |
<smallvec::SmallVec<[u8; 8]>>::triple Line | Count | Source | 1050 | 26.4k | fn triple(&self) -> (ConstNonNull<A::Item>, usize, usize) { | 1051 | | unsafe { | 1052 | 26.4k | if self.spilled() { | 1053 | 0 | let (ptr, len) = self.data.heap(); | 1054 | 0 | (ptr, len, self.capacity) | 1055 | | } else { | 1056 | 26.4k | (self.data.inline(), self.capacity, Self::inline_capacity()) | 1057 | | } | 1058 | | } | 1059 | 26.4k | } |
Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]>>::triple <smallvec::SmallVec<[u32; 2]>>::triple Line | Count | Source | 1050 | 12.3k | fn triple(&self) -> (ConstNonNull<A::Item>, usize, usize) { | 1051 | | unsafe { | 1052 | 12.3k | if self.spilled() { | 1053 | 11.2k | let (ptr, len) = self.data.heap(); | 1054 | 11.2k | (ptr, len, self.capacity) | 1055 | | } else { | 1056 | 1.07k | (self.data.inline(), self.capacity, Self::inline_capacity()) | 1057 | | } | 1058 | | } | 1059 | 12.3k | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::triple |
1060 | | |
1061 | | /// Returns a tuple with (data ptr, len ptr, capacity) |
1062 | | #[inline] |
1063 | 35.6M | fn triple_mut(&mut self) -> (NonNull<A::Item>, &mut usize, usize) { |
1064 | | unsafe { |
1065 | 35.6M | if self.spilled() { |
1066 | 1.29M | let (ptr, len_ptr) = self.data.heap_mut(); |
1067 | 1.29M | (ptr, len_ptr, self.capacity) |
1068 | | } else { |
1069 | 34.3M | ( |
1070 | 34.3M | self.data.inline_mut(), |
1071 | 34.3M | &mut self.capacity, |
1072 | 34.3M | Self::inline_capacity(), |
1073 | 34.3M | ) |
1074 | | } |
1075 | | } |
1076 | 35.6M | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::triple_mut Line | Count | Source | 1063 | 876k | fn triple_mut(&mut self) -> (NonNull<A::Item>, &mut usize, usize) { | 1064 | | unsafe { | 1065 | 876k | if self.spilled() { | 1066 | 1.05k | let (ptr, len_ptr) = self.data.heap_mut(); | 1067 | 1.05k | (ptr, len_ptr, self.capacity) | 1068 | | } else { | 1069 | 875k | ( | 1070 | 875k | self.data.inline_mut(), | 1071 | 875k | &mut self.capacity, | 1072 | 875k | Self::inline_capacity(), | 1073 | 875k | ) | 1074 | | } | 1075 | | } | 1076 | 876k | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]>>::triple_mut Line | Count | Source | 1063 | 2.61M | fn triple_mut(&mut self) -> (NonNull<A::Item>, &mut usize, usize) { | 1064 | | unsafe { | 1065 | 2.61M | if self.spilled() { | 1066 | 2.63k | let (ptr, len_ptr) = self.data.heap_mut(); | 1067 | 2.63k | (ptr, len_ptr, self.capacity) | 1068 | | } else { | 1069 | 2.61M | ( | 1070 | 2.61M | self.data.inline_mut(), | 1071 | 2.61M | &mut self.capacity, | 1072 | 2.61M | Self::inline_capacity(), | 1073 | 2.61M | ) | 1074 | | } | 1075 | | } | 1076 | 2.61M | } |
<smallvec::SmallVec<[u8; 64]>>::triple_mut Line | Count | Source | 1063 | 7.04M | fn triple_mut(&mut self) -> (NonNull<A::Item>, &mut usize, usize) { | 1064 | | unsafe { | 1065 | 7.04M | if self.spilled() { | 1066 | 734k | let (ptr, len_ptr) = self.data.heap_mut(); | 1067 | 734k | (ptr, len_ptr, self.capacity) | 1068 | | } else { | 1069 | 6.30M | ( | 1070 | 6.30M | self.data.inline_mut(), | 1071 | 6.30M | &mut self.capacity, | 1072 | 6.30M | Self::inline_capacity(), | 1073 | 6.30M | ) | 1074 | | } | 1075 | | } | 1076 | 7.04M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::triple_mut Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::triple_mut <smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]>>::triple_mut Line | Count | Source | 1063 | 2.73M | fn triple_mut(&mut self) -> (NonNull<A::Item>, &mut usize, usize) { | 1064 | | unsafe { | 1065 | 2.73M | if self.spilled() { | 1066 | 1.21k | let (ptr, len_ptr) = self.data.heap_mut(); | 1067 | 1.21k | (ptr, len_ptr, self.capacity) | 1068 | | } else { | 1069 | 2.73M | ( | 1070 | 2.73M | self.data.inline_mut(), | 1071 | 2.73M | &mut self.capacity, | 1072 | 2.73M | Self::inline_capacity(), | 1073 | 2.73M | ) | 1074 | | } | 1075 | | } | 1076 | 2.73M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]>>::triple_mut <smallvec::SmallVec<[u8; 16]>>::triple_mut Line | Count | Source | 1063 | 3.11M | fn triple_mut(&mut self) -> (NonNull<A::Item>, &mut usize, usize) { | 1064 | | unsafe { | 1065 | 3.11M | if self.spilled() { | 1066 | 201k | let (ptr, len_ptr) = self.data.heap_mut(); | 1067 | 201k | (ptr, len_ptr, self.capacity) | 1068 | | } else { | 1069 | 2.91M | ( | 1070 | 2.91M | self.data.inline_mut(), | 1071 | 2.91M | &mut self.capacity, | 1072 | 2.91M | Self::inline_capacity(), | 1073 | 2.91M | ) | 1074 | | } | 1075 | | } | 1076 | 3.11M | } |
<smallvec::SmallVec<[u8; 24]>>::triple_mut Line | Count | Source | 1063 | 19.1M | fn triple_mut(&mut self) -> (NonNull<A::Item>, &mut usize, usize) { | 1064 | | unsafe { | 1065 | 19.1M | if self.spilled() { | 1066 | 354k | let (ptr, len_ptr) = self.data.heap_mut(); | 1067 | 354k | (ptr, len_ptr, self.capacity) | 1068 | | } else { | 1069 | 18.8M | ( | 1070 | 18.8M | self.data.inline_mut(), | 1071 | 18.8M | &mut self.capacity, | 1072 | 18.8M | Self::inline_capacity(), | 1073 | 18.8M | ) | 1074 | | } | 1075 | | } | 1076 | 19.1M | } |
<smallvec::SmallVec<[u8; 8]>>::triple_mut Line | Count | Source | 1063 | 52.8k | fn triple_mut(&mut self) -> (NonNull<A::Item>, &mut usize, usize) { | 1064 | | unsafe { | 1065 | 52.8k | if self.spilled() { | 1066 | 0 | let (ptr, len_ptr) = self.data.heap_mut(); | 1067 | 0 | (ptr, len_ptr, self.capacity) | 1068 | | } else { | 1069 | 52.8k | ( | 1070 | 52.8k | self.data.inline_mut(), | 1071 | 52.8k | &mut self.capacity, | 1072 | 52.8k | Self::inline_capacity(), | 1073 | 52.8k | ) | 1074 | | } | 1075 | | } | 1076 | 52.8k | } |
Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]>>::triple_mut <smallvec::SmallVec<[u32; 2]>>::triple_mut Line | Count | Source | 1063 | 196 | fn triple_mut(&mut self) -> (NonNull<A::Item>, &mut usize, usize) { | 1064 | | unsafe { | 1065 | 196 | if self.spilled() { | 1066 | 124 | let (ptr, len_ptr) = self.data.heap_mut(); | 1067 | 124 | (ptr, len_ptr, self.capacity) | 1068 | | } else { | 1069 | 72 | ( | 1070 | 72 | self.data.inline_mut(), | 1071 | 72 | &mut self.capacity, | 1072 | 72 | Self::inline_capacity(), | 1073 | 72 | ) | 1074 | | } | 1075 | | } | 1076 | 196 | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::triple_mut |
1077 | | |
1078 | | /// Returns `true` if the data has spilled into a separate heap-allocated |
1079 | | /// buffer. |
1080 | | #[inline] |
1081 | 162M | pub fn spilled(&self) -> bool { |
1082 | 162M | self.capacity > Self::inline_capacity() |
1083 | 162M | } <smallvec::SmallVec<[u8; 64]>>::spilled Line | Count | Source | 1081 | 19.7M | pub fn spilled(&self) -> bool { | 1082 | 19.7M | self.capacity > Self::inline_capacity() | 1083 | 19.7M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::spilled <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::spilled Line | Count | Source | 1081 | 2.57M | pub fn spilled(&self) -> bool { | 1082 | 2.57M | self.capacity > Self::inline_capacity() | 1083 | 2.57M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::spilled <smallvec::SmallVec<[exr::meta::header::Header; 3]>>::spilled Line | Count | Source | 1081 | 9.68M | pub fn spilled(&self) -> bool { | 1082 | 9.68M | self.capacity > Self::inline_capacity() | 1083 | 9.68M | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]>>::spilled Line | Count | Source | 1081 | 5.11M | pub fn spilled(&self) -> bool { | 1082 | 5.11M | self.capacity > Self::inline_capacity() | 1083 | 5.11M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]>>::spilled <smallvec::SmallVec<[u8; 16]>>::spilled Line | Count | Source | 1081 | 4.53M | pub fn spilled(&self) -> bool { | 1082 | 4.53M | self.capacity > Self::inline_capacity() | 1083 | 4.53M | } |
<smallvec::SmallVec<[u8; 24]>>::spilled Line | Count | Source | 1081 | 120M | pub fn spilled(&self) -> bool { | 1082 | 120M | self.capacity > Self::inline_capacity() | 1083 | 120M | } |
<smallvec::SmallVec<[u8; 8]>>::spilled Line | Count | Source | 1081 | 105k | pub fn spilled(&self) -> bool { | 1082 | 105k | self.capacity > Self::inline_capacity() | 1083 | 105k | } |
Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]>>::spilled <smallvec::SmallVec<[u32; 2]>>::spilled Line | Count | Source | 1081 | 16.2k | pub fn spilled(&self) -> bool { | 1082 | 16.2k | self.capacity > Self::inline_capacity() | 1083 | 16.2k | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::spilled |
1084 | | |
1085 | | /// Creates a draining iterator that removes the specified range in the |
1086 | | /// vector and yields the removed items. |
1087 | | /// |
1088 | | /// Note 1: The element range is removed even if the iterator is only |
1089 | | /// partially consumed or not consumed at all. |
1090 | | /// |
1091 | | /// Note 2: It is unspecified how many elements are removed from the vector |
1092 | | /// if the `Drain` value is leaked. |
1093 | | /// |
1094 | | /// # Panics |
1095 | | /// |
1096 | | /// Panics if the starting point is greater than the end point or if |
1097 | | /// the end point is greater than the length of the vector. |
1098 | 0 | pub fn drain<R>(&mut self, range: R) -> Drain<'_, A> |
1099 | 0 | where |
1100 | 0 | R: RangeBounds<usize>, |
1101 | | { |
1102 | | use core::ops::Bound::*; |
1103 | | |
1104 | 0 | let len = self.len(); |
1105 | 0 | let start = match range.start_bound() { |
1106 | 0 | Included(&n) => n, |
1107 | 0 | Excluded(&n) => n.checked_add(1).expect("Range start out of bounds"), |
1108 | 0 | Unbounded => 0, |
1109 | | }; |
1110 | 0 | let end = match range.end_bound() { |
1111 | 0 | Included(&n) => n.checked_add(1).expect("Range end out of bounds"), |
1112 | 0 | Excluded(&n) => n, |
1113 | 0 | Unbounded => len, |
1114 | | }; |
1115 | | |
1116 | 0 | assert!(start <= end); |
1117 | 0 | assert!(end <= len); |
1118 | | |
1119 | | unsafe { |
1120 | 0 | self.set_len(start); |
1121 | | |
1122 | 0 | let range_slice = slice::from_raw_parts(self.as_ptr().add(start), end - start); |
1123 | | |
1124 | 0 | Drain { |
1125 | 0 | tail_start: end, |
1126 | 0 | tail_len: len - end, |
1127 | 0 | iter: range_slice.iter(), |
1128 | 0 | // Since self is a &mut, passing it to a function would invalidate the slice |
1129 | 0 | // iterator. |
1130 | 0 | vec: NonNull::new_unchecked(self as *mut _), |
1131 | 0 | } |
1132 | | } |
1133 | 0 | } |
1134 | | |
1135 | | #[cfg(feature = "drain_filter")] |
1136 | | /// Creates an iterator which uses a closure to determine if an element |
1137 | | /// should be removed. |
1138 | | /// |
1139 | | /// If the closure returns true, the element is removed and yielded. If the |
1140 | | /// closure returns false, the element will remain in the vector and |
1141 | | /// will not be yielded by the iterator. |
1142 | | /// |
1143 | | /// Using this method is equivalent to the following code: |
1144 | | /// ``` |
1145 | | /// # use smallvec::SmallVec; |
1146 | | /// # let some_predicate = |x: &mut i32| { *x == 2 || *x == 3 || *x == 6 }; |
1147 | | /// # let mut vec: SmallVec<[i32; 8]> = SmallVec::from_slice(&[1i32, 2, 3, 4, 5, 6]); |
1148 | | /// let mut i = 0; |
1149 | | /// while i < vec.len() { |
1150 | | /// if some_predicate(&mut vec[i]) { |
1151 | | /// let val = vec.remove(i); |
1152 | | /// // your code here |
1153 | | /// } else { |
1154 | | /// i += 1; |
1155 | | /// } |
1156 | | /// } |
1157 | | /// |
1158 | | /// # assert_eq!(vec, SmallVec::<[i32; 8]>::from_slice(&[1i32, 4, 5])); |
1159 | | /// ``` |
1160 | | /// /// |
1161 | | /// But `drain_filter` is easier to use. `drain_filter` is also more |
1162 | | /// efficient, because it can backshift the elements of the array in |
1163 | | /// bulk. |
1164 | | /// |
1165 | | /// Note that `drain_filter` also lets you mutate every element in the |
1166 | | /// filter closure, regardless of whether you choose to keep or remove |
1167 | | /// it. |
1168 | | /// |
1169 | | /// # Examples |
1170 | | /// |
1171 | | /// Splitting an array into evens and odds, reusing the original allocation: |
1172 | | /// |
1173 | | /// ``` |
1174 | | /// # use smallvec::SmallVec; |
1175 | | /// let mut numbers: SmallVec<[i32; 16]> = |
1176 | | /// SmallVec::from_slice(&[1i32, 2, 3, 4, 5, 6, 8, 9, 11, 13, 14, 15]); |
1177 | | /// |
1178 | | /// let evens = numbers |
1179 | | /// .drain_filter(|x| *x % 2 == 0) |
1180 | | /// .collect::<SmallVec<[i32; 16]>>(); |
1181 | | /// let odds = numbers; |
1182 | | /// |
1183 | | /// assert_eq!( |
1184 | | /// evens, |
1185 | | /// SmallVec::<[i32; 16]>::from_slice(&[2i32, 4, 6, 8, 14]) |
1186 | | /// ); |
1187 | | /// assert_eq!( |
1188 | | /// odds, |
1189 | | /// SmallVec::<[i32; 16]>::from_slice(&[1i32, 3, 5, 9, 11, 13, 15]) |
1190 | | /// ); |
1191 | | /// ``` |
1192 | | pub fn drain_filter<F>(&mut self, filter: F) -> DrainFilter<'_, A, F> |
1193 | | where |
1194 | | F: FnMut(&mut A::Item) -> bool, |
1195 | | { |
1196 | | let old_len = self.len(); |
1197 | | |
1198 | | // Guard against us getting leaked (leak amplification) |
1199 | | unsafe { |
1200 | | self.set_len(0); |
1201 | | } |
1202 | | |
1203 | | DrainFilter { |
1204 | | vec: self, |
1205 | | idx: 0, |
1206 | | del: 0, |
1207 | | old_len, |
1208 | | pred: filter, |
1209 | | panic_flag: false, |
1210 | | } |
1211 | | } |
1212 | | |
1213 | | /// Append an item to the vector. |
1214 | | #[inline] |
1215 | 40.8M | pub fn push(&mut self, value: A::Item) { |
1216 | | unsafe { |
1217 | 40.8M | if self.spilled() { |
1218 | 7.42M | let (mut ptr, mut len_ptr) = self.data.heap_mut(); |
1219 | 7.42M | if *len_ptr == self.capacity { |
1220 | 261k | self.reserve_one_unchecked(); |
1221 | 261k | let (heap_ptr, heap_len) = self.data.heap_mut(); |
1222 | 261k | ptr = heap_ptr; |
1223 | 261k | len_ptr = heap_len; |
1224 | 7.16M | } |
1225 | 7.42M | ptr::write(ptr.as_ptr().add(*len_ptr), value); |
1226 | 7.42M | *len_ptr += 1; |
1227 | | } else { |
1228 | 33.4M | let mut ptr = self.data.inline_mut(); |
1229 | 33.4M | let mut len_ptr = &mut self.capacity; |
1230 | 33.4M | if *len_ptr == Self::inline_capacity() { |
1231 | 264k | self.reserve_one_unchecked(); |
1232 | 264k | let (heap_ptr, heap_len) = self.data.heap_mut(); |
1233 | 264k | ptr = heap_ptr; |
1234 | 264k | len_ptr = heap_len; |
1235 | 33.1M | } |
1236 | 33.4M | ptr::write(ptr.as_ptr().add(*len_ptr), value); |
1237 | 33.4M | *len_ptr += 1; |
1238 | | }; |
1239 | | } |
1240 | 40.8M | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::push Line | Count | Source | 1215 | 12.8k | pub fn push(&mut self, value: A::Item) { | 1216 | | unsafe { | 1217 | 12.8k | if self.spilled() { | 1218 | 12.4k | let (mut ptr, mut len_ptr) = self.data.heap_mut(); | 1219 | 12.4k | if *len_ptr == self.capacity { | 1220 | 1.05k | self.reserve_one_unchecked(); | 1221 | 1.05k | let (heap_ptr, heap_len) = self.data.heap_mut(); | 1222 | 1.05k | ptr = heap_ptr; | 1223 | 1.05k | len_ptr = heap_len; | 1224 | 11.3k | } | 1225 | 12.4k | ptr::write(ptr.as_ptr().add(*len_ptr), value); | 1226 | 12.4k | *len_ptr += 1; | 1227 | | } else { | 1228 | 429 | let mut ptr = self.data.inline_mut(); | 1229 | 429 | let mut len_ptr = &mut self.capacity; | 1230 | 429 | if *len_ptr == Self::inline_capacity() { | 1231 | 429 | self.reserve_one_unchecked(); | 1232 | 429 | let (heap_ptr, heap_len) = self.data.heap_mut(); | 1233 | 429 | ptr = heap_ptr; | 1234 | 429 | len_ptr = heap_len; | 1235 | 429 | } | 1236 | 429 | ptr::write(ptr.as_ptr().add(*len_ptr), value); | 1237 | 429 | *len_ptr += 1; | 1238 | | }; | 1239 | | } | 1240 | 12.8k | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]>>::push Line | Count | Source | 1215 | 38.3k | pub fn push(&mut self, value: A::Item) { | 1216 | | unsafe { | 1217 | 38.3k | if self.spilled() { | 1218 | 32.1k | let (mut ptr, mut len_ptr) = self.data.heap_mut(); | 1219 | 32.1k | if *len_ptr == self.capacity { | 1220 | 2.27k | self.reserve_one_unchecked(); | 1221 | 2.27k | let (heap_ptr, heap_len) = self.data.heap_mut(); | 1222 | 2.27k | ptr = heap_ptr; | 1223 | 2.27k | len_ptr = heap_len; | 1224 | 29.8k | } | 1225 | 32.1k | ptr::write(ptr.as_ptr().add(*len_ptr), value); | 1226 | 32.1k | *len_ptr += 1; | 1227 | | } else { | 1228 | 6.21k | let mut ptr = self.data.inline_mut(); | 1229 | 6.21k | let mut len_ptr = &mut self.capacity; | 1230 | 6.21k | if *len_ptr == Self::inline_capacity() { | 1231 | 808 | self.reserve_one_unchecked(); | 1232 | 808 | let (heap_ptr, heap_len) = self.data.heap_mut(); | 1233 | 808 | ptr = heap_ptr; | 1234 | 808 | len_ptr = heap_len; | 1235 | 5.40k | } | 1236 | 6.21k | ptr::write(ptr.as_ptr().add(*len_ptr), value); | 1237 | 6.21k | *len_ptr += 1; | 1238 | | }; | 1239 | | } | 1240 | 38.3k | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]>>::push Line | Count | Source | 1215 | 196k | pub fn push(&mut self, value: A::Item) { | 1216 | | unsafe { | 1217 | 196k | if self.spilled() { | 1218 | 5.95k | let (mut ptr, mut len_ptr) = self.data.heap_mut(); | 1219 | 5.95k | if *len_ptr == self.capacity { | 1220 | 1.20k | self.reserve_one_unchecked(); | 1221 | 1.20k | let (heap_ptr, heap_len) = self.data.heap_mut(); | 1222 | 1.20k | ptr = heap_ptr; | 1223 | 1.20k | len_ptr = heap_len; | 1224 | 4.75k | } | 1225 | 5.95k | ptr::write(ptr.as_ptr().add(*len_ptr), value); | 1226 | 5.95k | *len_ptr += 1; | 1227 | | } else { | 1228 | 190k | let mut ptr = self.data.inline_mut(); | 1229 | 190k | let mut len_ptr = &mut self.capacity; | 1230 | 190k | if *len_ptr == Self::inline_capacity() { | 1231 | 3.51k | self.reserve_one_unchecked(); | 1232 | 3.51k | let (heap_ptr, heap_len) = self.data.heap_mut(); | 1233 | 3.51k | ptr = heap_ptr; | 1234 | 3.51k | len_ptr = heap_len; | 1235 | 186k | } | 1236 | 190k | ptr::write(ptr.as_ptr().add(*len_ptr), value); | 1237 | 190k | *len_ptr += 1; | 1238 | | }; | 1239 | | } | 1240 | 196k | } |
Unexecuted instantiation: <smallvec::SmallVec<[u8; 16]>>::push Unexecuted instantiation: <smallvec::SmallVec<[u8; 64]>>::push Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::push Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::push Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]>>::push <smallvec::SmallVec<[u8; 24]>>::push Line | Count | Source | 1215 | 40.6M | pub fn push(&mut self, value: A::Item) { | 1216 | | unsafe { | 1217 | 40.6M | if self.spilled() { | 1218 | 7.37M | let (mut ptr, mut len_ptr) = self.data.heap_mut(); | 1219 | 7.37M | if *len_ptr == self.capacity { | 1220 | 256k | self.reserve_one_unchecked(); | 1221 | 256k | let (heap_ptr, heap_len) = self.data.heap_mut(); | 1222 | 256k | ptr = heap_ptr; | 1223 | 256k | len_ptr = heap_len; | 1224 | 7.11M | } | 1225 | 7.37M | ptr::write(ptr.as_ptr().add(*len_ptr), value); | 1226 | 7.37M | *len_ptr += 1; | 1227 | | } else { | 1228 | 33.2M | let mut ptr = self.data.inline_mut(); | 1229 | 33.2M | let mut len_ptr = &mut self.capacity; | 1230 | 33.2M | if *len_ptr == Self::inline_capacity() { | 1231 | 259k | self.reserve_one_unchecked(); | 1232 | 259k | let (heap_ptr, heap_len) = self.data.heap_mut(); | 1233 | 259k | ptr = heap_ptr; | 1234 | 259k | len_ptr = heap_len; | 1235 | 32.9M | } | 1236 | 33.2M | ptr::write(ptr.as_ptr().add(*len_ptr), value); | 1237 | 33.2M | *len_ptr += 1; | 1238 | | }; | 1239 | | } | 1240 | 40.6M | } |
Unexecuted instantiation: <smallvec::SmallVec<[u8; 8]>>::push Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]>>::push <smallvec::SmallVec<[u32; 2]>>::push Line | Count | Source | 1215 | 3.55k | pub fn push(&mut self, value: A::Item) { | 1216 | | unsafe { | 1217 | 3.55k | if self.spilled() { | 1218 | 3.43k | let (mut ptr, mut len_ptr) = self.data.heap_mut(); | 1219 | 3.43k | if *len_ptr == self.capacity { | 1220 | 124 | self.reserve_one_unchecked(); | 1221 | 124 | let (heap_ptr, heap_len) = self.data.heap_mut(); | 1222 | 124 | ptr = heap_ptr; | 1223 | 124 | len_ptr = heap_len; | 1224 | 3.30k | } | 1225 | 3.43k | ptr::write(ptr.as_ptr().add(*len_ptr), value); | 1226 | 3.43k | *len_ptr += 1; | 1227 | | } else { | 1228 | 126 | let mut ptr = self.data.inline_mut(); | 1229 | 126 | let mut len_ptr = &mut self.capacity; | 1230 | 126 | if *len_ptr == Self::inline_capacity() { | 1231 | 25 | self.reserve_one_unchecked(); | 1232 | 25 | let (heap_ptr, heap_len) = self.data.heap_mut(); | 1233 | 25 | ptr = heap_ptr; | 1234 | 25 | len_ptr = heap_len; | 1235 | 101 | } | 1236 | 126 | ptr::write(ptr.as_ptr().add(*len_ptr), value); | 1237 | 126 | *len_ptr += 1; | 1238 | | }; | 1239 | | } | 1240 | 3.55k | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::push |
1241 | | |
1242 | | /// Remove an item from the end of the vector and return it, or None if |
1243 | | /// empty. |
1244 | | #[inline] |
1245 | 0 | pub fn pop(&mut self) -> Option<A::Item> { |
1246 | | unsafe { |
1247 | 0 | let (ptr, len_ptr, _) = self.triple_mut(); |
1248 | 0 | let ptr: *const _ = ptr.as_ptr(); |
1249 | 0 | if *len_ptr == 0 { |
1250 | 0 | return None; |
1251 | 0 | } |
1252 | 0 | let last_index = *len_ptr - 1; |
1253 | 0 | *len_ptr = last_index; |
1254 | 0 | Some(ptr::read(ptr.add(last_index))) |
1255 | | } |
1256 | 0 | } |
1257 | | |
1258 | | /// Moves all the elements of `other` into `self`, leaving `other` empty. |
1259 | | /// |
1260 | | /// # Example |
1261 | | /// |
1262 | | /// ``` |
1263 | | /// # use smallvec::{SmallVec, smallvec}; |
1264 | | /// let mut v0: SmallVec<[u8; 16]> = smallvec![1, 2, 3]; |
1265 | | /// let mut v1: SmallVec<[u8; 32]> = smallvec![4, 5, 6]; |
1266 | | /// v0.append(&mut v1); |
1267 | | /// assert_eq!(*v0, [1, 2, 3, 4, 5, 6]); |
1268 | | /// assert_eq!(*v1, []); |
1269 | | /// ``` |
1270 | 0 | pub fn append<B>(&mut self, other: &mut SmallVec<B>) |
1271 | 0 | where |
1272 | 0 | B: Array<Item = A::Item>, |
1273 | | { |
1274 | 0 | self.extend(other.drain(..)) |
1275 | 0 | } |
1276 | | |
1277 | | /// Re-allocate to set the capacity to `max(new_cap, inline_size())`. |
1278 | | /// |
1279 | | /// Panics if `new_cap` is less than the vector's length |
1280 | | /// or if the capacity computation overflows `usize`. |
1281 | 0 | pub fn grow(&mut self, new_cap: usize) { |
1282 | 0 | infallible(self.try_grow(new_cap)) |
1283 | 0 | } |
1284 | | |
1285 | | /// Re-allocate to set the capacity to `max(new_cap, inline_size())`. |
1286 | | /// |
1287 | | /// Panics if `new_cap` is less than the vector's length |
1288 | 913k | pub fn try_grow(&mut self, new_cap: usize) -> Result<(), CollectionAllocErr> { |
1289 | | unsafe { |
1290 | 913k | let unspilled = !self.spilled(); |
1291 | 913k | let (ptr, &mut len, cap) = self.triple_mut(); |
1292 | 913k | assert!(new_cap >= len); |
1293 | 913k | if new_cap <= Self::inline_capacity() { |
1294 | 0 | if unspilled { |
1295 | 0 | return Ok(()); |
1296 | 0 | } |
1297 | 0 | self.data = SmallVecData::empty(); |
1298 | 0 | ptr::copy_nonoverlapping(ptr.as_ptr(), self.data.inline_mut().as_ptr(), len); |
1299 | 0 | self.capacity = len; |
1300 | 0 | deallocate(ptr, cap); |
1301 | 913k | } else if new_cap != cap { |
1302 | 913k | let layout = layout_array::<A::Item>(new_cap)?; |
1303 | 913k | debug_assert!(layout.size() > 0); |
1304 | | let new_alloc; |
1305 | 913k | if unspilled { |
1306 | 617k | new_alloc = NonNull::new(alloc::alloc::alloc(layout)) |
1307 | 617k | .ok_or(CollectionAllocErr::AllocErr { layout })? |
1308 | 617k | .cast(); |
1309 | 617k | ptr::copy_nonoverlapping(ptr.as_ptr(), new_alloc.as_ptr(), len); |
1310 | | } else { |
1311 | | // This should never fail since the same succeeded |
1312 | | // when previously allocating `ptr`. |
1313 | 296k | let old_layout = layout_array::<A::Item>(cap)?; |
1314 | | |
1315 | 296k | let new_ptr = |
1316 | 296k | alloc::alloc::realloc(ptr.as_ptr() as *mut u8, old_layout, layout.size()); |
1317 | 296k | new_alloc = NonNull::new(new_ptr) |
1318 | 296k | .ok_or(CollectionAllocErr::AllocErr { layout })? |
1319 | 296k | .cast(); |
1320 | | } |
1321 | 913k | self.data = SmallVecData::from_heap(new_alloc, len); |
1322 | 913k | self.capacity = new_cap; |
1323 | 0 | } |
1324 | 913k | Ok(()) |
1325 | | } |
1326 | 913k | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::try_grow Line | Count | Source | 1288 | 1.48k | pub fn try_grow(&mut self, new_cap: usize) -> Result<(), CollectionAllocErr> { | 1289 | | unsafe { | 1290 | 1.48k | let unspilled = !self.spilled(); | 1291 | 1.48k | let (ptr, &mut len, cap) = self.triple_mut(); | 1292 | 1.48k | assert!(new_cap >= len); | 1293 | 1.48k | if new_cap <= Self::inline_capacity() { | 1294 | 0 | if unspilled { | 1295 | 0 | return Ok(()); | 1296 | 0 | } | 1297 | 0 | self.data = SmallVecData::empty(); | 1298 | 0 | ptr::copy_nonoverlapping(ptr.as_ptr(), self.data.inline_mut().as_ptr(), len); | 1299 | 0 | self.capacity = len; | 1300 | 0 | deallocate(ptr, cap); | 1301 | 1.48k | } else if new_cap != cap { | 1302 | 1.48k | let layout = layout_array::<A::Item>(new_cap)?; | 1303 | 1.48k | debug_assert!(layout.size() > 0); | 1304 | | let new_alloc; | 1305 | 1.48k | if unspilled { | 1306 | 429 | new_alloc = NonNull::new(alloc::alloc::alloc(layout)) | 1307 | 429 | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1308 | 429 | .cast(); | 1309 | 429 | ptr::copy_nonoverlapping(ptr.as_ptr(), new_alloc.as_ptr(), len); | 1310 | | } else { | 1311 | | // This should never fail since the same succeeded | 1312 | | // when previously allocating `ptr`. | 1313 | 1.05k | let old_layout = layout_array::<A::Item>(cap)?; | 1314 | | | 1315 | 1.05k | let new_ptr = | 1316 | 1.05k | alloc::alloc::realloc(ptr.as_ptr() as *mut u8, old_layout, layout.size()); | 1317 | 1.05k | new_alloc = NonNull::new(new_ptr) | 1318 | 1.05k | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1319 | 1.05k | .cast(); | 1320 | | } | 1321 | 1.48k | self.data = SmallVecData::from_heap(new_alloc, len); | 1322 | 1.48k | self.capacity = new_cap; | 1323 | 0 | } | 1324 | 1.48k | Ok(()) | 1325 | | } | 1326 | 1.48k | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]>>::try_grow Line | Count | Source | 1288 | 3.44k | pub fn try_grow(&mut self, new_cap: usize) -> Result<(), CollectionAllocErr> { | 1289 | | unsafe { | 1290 | 3.44k | let unspilled = !self.spilled(); | 1291 | 3.44k | let (ptr, &mut len, cap) = self.triple_mut(); | 1292 | 3.44k | assert!(new_cap >= len); | 1293 | 3.44k | if new_cap <= Self::inline_capacity() { | 1294 | 0 | if unspilled { | 1295 | 0 | return Ok(()); | 1296 | 0 | } | 1297 | 0 | self.data = SmallVecData::empty(); | 1298 | 0 | ptr::copy_nonoverlapping(ptr.as_ptr(), self.data.inline_mut().as_ptr(), len); | 1299 | 0 | self.capacity = len; | 1300 | 0 | deallocate(ptr, cap); | 1301 | 3.44k | } else if new_cap != cap { | 1302 | 3.44k | let layout = layout_array::<A::Item>(new_cap)?; | 1303 | 3.44k | debug_assert!(layout.size() > 0); | 1304 | | let new_alloc; | 1305 | 3.44k | if unspilled { | 1306 | 1.16k | new_alloc = NonNull::new(alloc::alloc::alloc(layout)) | 1307 | 1.16k | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1308 | 1.16k | .cast(); | 1309 | 1.16k | ptr::copy_nonoverlapping(ptr.as_ptr(), new_alloc.as_ptr(), len); | 1310 | | } else { | 1311 | | // This should never fail since the same succeeded | 1312 | | // when previously allocating `ptr`. | 1313 | 2.27k | let old_layout = layout_array::<A::Item>(cap)?; | 1314 | | | 1315 | 2.27k | let new_ptr = | 1316 | 2.27k | alloc::alloc::realloc(ptr.as_ptr() as *mut u8, old_layout, layout.size()); | 1317 | 2.27k | new_alloc = NonNull::new(new_ptr) | 1318 | 2.27k | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1319 | 2.27k | .cast(); | 1320 | | } | 1321 | 3.44k | self.data = SmallVecData::from_heap(new_alloc, len); | 1322 | 3.44k | self.capacity = new_cap; | 1323 | 0 | } | 1324 | 3.44k | Ok(()) | 1325 | | } | 1326 | 3.44k | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]>>::try_grow Line | Count | Source | 1288 | 4.72k | pub fn try_grow(&mut self, new_cap: usize) -> Result<(), CollectionAllocErr> { | 1289 | | unsafe { | 1290 | 4.72k | let unspilled = !self.spilled(); | 1291 | 4.72k | let (ptr, &mut len, cap) = self.triple_mut(); | 1292 | 4.72k | assert!(new_cap >= len); | 1293 | 4.72k | if new_cap <= Self::inline_capacity() { | 1294 | 0 | if unspilled { | 1295 | 0 | return Ok(()); | 1296 | 0 | } | 1297 | 0 | self.data = SmallVecData::empty(); | 1298 | 0 | ptr::copy_nonoverlapping(ptr.as_ptr(), self.data.inline_mut().as_ptr(), len); | 1299 | 0 | self.capacity = len; | 1300 | 0 | deallocate(ptr, cap); | 1301 | 4.72k | } else if new_cap != cap { | 1302 | 4.72k | let layout = layout_array::<A::Item>(new_cap)?; | 1303 | 4.72k | debug_assert!(layout.size() > 0); | 1304 | | let new_alloc; | 1305 | 4.72k | if unspilled { | 1306 | 3.51k | new_alloc = NonNull::new(alloc::alloc::alloc(layout)) | 1307 | 3.51k | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1308 | 3.51k | .cast(); | 1309 | 3.51k | ptr::copy_nonoverlapping(ptr.as_ptr(), new_alloc.as_ptr(), len); | 1310 | | } else { | 1311 | | // This should never fail since the same succeeded | 1312 | | // when previously allocating `ptr`. | 1313 | 1.20k | let old_layout = layout_array::<A::Item>(cap)?; | 1314 | | | 1315 | 1.20k | let new_ptr = | 1316 | 1.20k | alloc::alloc::realloc(ptr.as_ptr() as *mut u8, old_layout, layout.size()); | 1317 | 1.20k | new_alloc = NonNull::new(new_ptr) | 1318 | 1.20k | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1319 | 1.20k | .cast(); | 1320 | | } | 1321 | 4.72k | self.data = SmallVecData::from_heap(new_alloc, len); | 1322 | 4.72k | self.capacity = new_cap; | 1323 | 0 | } | 1324 | 4.72k | Ok(()) | 1325 | | } | 1326 | 4.72k | } |
<smallvec::SmallVec<[u8; 16]>>::try_grow Line | Count | Source | 1288 | 201k | pub fn try_grow(&mut self, new_cap: usize) -> Result<(), CollectionAllocErr> { | 1289 | | unsafe { | 1290 | 201k | let unspilled = !self.spilled(); | 1291 | 201k | let (ptr, &mut len, cap) = self.triple_mut(); | 1292 | 201k | assert!(new_cap >= len); | 1293 | 201k | if new_cap <= Self::inline_capacity() { | 1294 | 0 | if unspilled { | 1295 | 0 | return Ok(()); | 1296 | 0 | } | 1297 | 0 | self.data = SmallVecData::empty(); | 1298 | 0 | ptr::copy_nonoverlapping(ptr.as_ptr(), self.data.inline_mut().as_ptr(), len); | 1299 | 0 | self.capacity = len; | 1300 | 0 | deallocate(ptr, cap); | 1301 | 201k | } else if new_cap != cap { | 1302 | 201k | let layout = layout_array::<A::Item>(new_cap)?; | 1303 | 201k | debug_assert!(layout.size() > 0); | 1304 | | let new_alloc; | 1305 | 201k | if unspilled { | 1306 | 201k | new_alloc = NonNull::new(alloc::alloc::alloc(layout)) | 1307 | 201k | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1308 | 201k | .cast(); | 1309 | 201k | ptr::copy_nonoverlapping(ptr.as_ptr(), new_alloc.as_ptr(), len); | 1310 | | } else { | 1311 | | // This should never fail since the same succeeded | 1312 | | // when previously allocating `ptr`. | 1313 | 0 | let old_layout = layout_array::<A::Item>(cap)?; | 1314 | | | 1315 | 0 | let new_ptr = | 1316 | 0 | alloc::alloc::realloc(ptr.as_ptr() as *mut u8, old_layout, layout.size()); | 1317 | 0 | new_alloc = NonNull::new(new_ptr) | 1318 | 0 | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1319 | 0 | .cast(); | 1320 | | } | 1321 | 201k | self.data = SmallVecData::from_heap(new_alloc, len); | 1322 | 201k | self.capacity = new_cap; | 1323 | 0 | } | 1324 | 201k | Ok(()) | 1325 | | } | 1326 | 201k | } |
<smallvec::SmallVec<[u8; 64]>>::try_grow Line | Count | Source | 1288 | 88.3k | pub fn try_grow(&mut self, new_cap: usize) -> Result<(), CollectionAllocErr> { | 1289 | | unsafe { | 1290 | 88.3k | let unspilled = !self.spilled(); | 1291 | 88.3k | let (ptr, &mut len, cap) = self.triple_mut(); | 1292 | 88.3k | assert!(new_cap >= len); | 1293 | 88.3k | if new_cap <= Self::inline_capacity() { | 1294 | 0 | if unspilled { | 1295 | 0 | return Ok(()); | 1296 | 0 | } | 1297 | 0 | self.data = SmallVecData::empty(); | 1298 | 0 | ptr::copy_nonoverlapping(ptr.as_ptr(), self.data.inline_mut().as_ptr(), len); | 1299 | 0 | self.capacity = len; | 1300 | 0 | deallocate(ptr, cap); | 1301 | 88.3k | } else if new_cap != cap { | 1302 | 88.3k | let layout = layout_array::<A::Item>(new_cap)?; | 1303 | 88.3k | debug_assert!(layout.size() > 0); | 1304 | | let new_alloc; | 1305 | 88.3k | if unspilled { | 1306 | 53.6k | new_alloc = NonNull::new(alloc::alloc::alloc(layout)) | 1307 | 53.6k | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1308 | 53.6k | .cast(); | 1309 | 53.6k | ptr::copy_nonoverlapping(ptr.as_ptr(), new_alloc.as_ptr(), len); | 1310 | | } else { | 1311 | | // This should never fail since the same succeeded | 1312 | | // when previously allocating `ptr`. | 1313 | 34.7k | let old_layout = layout_array::<A::Item>(cap)?; | 1314 | | | 1315 | 34.7k | let new_ptr = | 1316 | 34.7k | alloc::alloc::realloc(ptr.as_ptr() as *mut u8, old_layout, layout.size()); | 1317 | 34.7k | new_alloc = NonNull::new(new_ptr) | 1318 | 34.7k | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1319 | 34.7k | .cast(); | 1320 | | } | 1321 | 88.3k | self.data = SmallVecData::from_heap(new_alloc, len); | 1322 | 88.3k | self.capacity = new_cap; | 1323 | 0 | } | 1324 | 88.3k | Ok(()) | 1325 | | } | 1326 | 88.3k | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::try_grow Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::try_grow Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]>>::try_grow <smallvec::SmallVec<[u8; 24]>>::try_grow Line | Count | Source | 1288 | 613k | pub fn try_grow(&mut self, new_cap: usize) -> Result<(), CollectionAllocErr> { | 1289 | | unsafe { | 1290 | 613k | let unspilled = !self.spilled(); | 1291 | 613k | let (ptr, &mut len, cap) = self.triple_mut(); | 1292 | 613k | assert!(new_cap >= len); | 1293 | 613k | if new_cap <= Self::inline_capacity() { | 1294 | 0 | if unspilled { | 1295 | 0 | return Ok(()); | 1296 | 0 | } | 1297 | 0 | self.data = SmallVecData::empty(); | 1298 | 0 | ptr::copy_nonoverlapping(ptr.as_ptr(), self.data.inline_mut().as_ptr(), len); | 1299 | 0 | self.capacity = len; | 1300 | 0 | deallocate(ptr, cap); | 1301 | 613k | } else if new_cap != cap { | 1302 | 613k | let layout = layout_array::<A::Item>(new_cap)?; | 1303 | 613k | debug_assert!(layout.size() > 0); | 1304 | | let new_alloc; | 1305 | 613k | if unspilled { | 1306 | 356k | new_alloc = NonNull::new(alloc::alloc::alloc(layout)) | 1307 | 356k | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1308 | 356k | .cast(); | 1309 | 356k | ptr::copy_nonoverlapping(ptr.as_ptr(), new_alloc.as_ptr(), len); | 1310 | | } else { | 1311 | | // This should never fail since the same succeeded | 1312 | | // when previously allocating `ptr`. | 1313 | 256k | let old_layout = layout_array::<A::Item>(cap)?; | 1314 | | | 1315 | 256k | let new_ptr = | 1316 | 256k | alloc::alloc::realloc(ptr.as_ptr() as *mut u8, old_layout, layout.size()); | 1317 | 256k | new_alloc = NonNull::new(new_ptr) | 1318 | 256k | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1319 | 256k | .cast(); | 1320 | | } | 1321 | 613k | self.data = SmallVecData::from_heap(new_alloc, len); | 1322 | 613k | self.capacity = new_cap; | 1323 | 0 | } | 1324 | 613k | Ok(()) | 1325 | | } | 1326 | 613k | } |
Unexecuted instantiation: <smallvec::SmallVec<[u8; 8]>>::try_grow Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]>>::try_grow <smallvec::SmallVec<[u32; 2]>>::try_grow Line | Count | Source | 1288 | 149 | pub fn try_grow(&mut self, new_cap: usize) -> Result<(), CollectionAllocErr> { | 1289 | | unsafe { | 1290 | 149 | let unspilled = !self.spilled(); | 1291 | 149 | let (ptr, &mut len, cap) = self.triple_mut(); | 1292 | 149 | assert!(new_cap >= len); | 1293 | 149 | if new_cap <= Self::inline_capacity() { | 1294 | 0 | if unspilled { | 1295 | 0 | return Ok(()); | 1296 | 0 | } | 1297 | 0 | self.data = SmallVecData::empty(); | 1298 | 0 | ptr::copy_nonoverlapping(ptr.as_ptr(), self.data.inline_mut().as_ptr(), len); | 1299 | 0 | self.capacity = len; | 1300 | 0 | deallocate(ptr, cap); | 1301 | 149 | } else if new_cap != cap { | 1302 | 149 | let layout = layout_array::<A::Item>(new_cap)?; | 1303 | 149 | debug_assert!(layout.size() > 0); | 1304 | | let new_alloc; | 1305 | 149 | if unspilled { | 1306 | 25 | new_alloc = NonNull::new(alloc::alloc::alloc(layout)) | 1307 | 25 | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1308 | 25 | .cast(); | 1309 | 25 | ptr::copy_nonoverlapping(ptr.as_ptr(), new_alloc.as_ptr(), len); | 1310 | | } else { | 1311 | | // This should never fail since the same succeeded | 1312 | | // when previously allocating `ptr`. | 1313 | 124 | let old_layout = layout_array::<A::Item>(cap)?; | 1314 | | | 1315 | 124 | let new_ptr = | 1316 | 124 | alloc::alloc::realloc(ptr.as_ptr() as *mut u8, old_layout, layout.size()); | 1317 | 124 | new_alloc = NonNull::new(new_ptr) | 1318 | 124 | .ok_or(CollectionAllocErr::AllocErr { layout })? | 1319 | 124 | .cast(); | 1320 | | } | 1321 | 149 | self.data = SmallVecData::from_heap(new_alloc, len); | 1322 | 149 | self.capacity = new_cap; | 1323 | 0 | } | 1324 | 149 | Ok(()) | 1325 | | } | 1326 | 149 | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::try_grow |
1327 | | |
1328 | | /// Reserve capacity for `additional` more elements to be inserted. |
1329 | | /// |
1330 | | /// May reserve more space to avoid frequent reallocations. |
1331 | | /// |
1332 | | /// Panics if the capacity computation overflows `usize`. |
1333 | | #[inline] |
1334 | 9.49M | pub fn reserve(&mut self, additional: usize) { |
1335 | 9.49M | infallible(self.try_reserve(additional)) |
1336 | 9.49M | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::reserve Line | Count | Source | 1334 | 3.04k | pub fn reserve(&mut self, additional: usize) { | 1335 | 3.04k | infallible(self.try_reserve(additional)) | 1336 | 3.04k | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]>>::reserve Line | Count | Source | 1334 | 868k | pub fn reserve(&mut self, additional: usize) { | 1335 | 868k | infallible(self.try_reserve(additional)) | 1336 | 868k | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]>>::reserve Line | Count | Source | 1334 | 884k | pub fn reserve(&mut self, additional: usize) { | 1335 | 884k | infallible(self.try_reserve(additional)) | 1336 | 884k | } |
<smallvec::SmallVec<[u8; 16]>>::reserve Line | Count | Source | 1334 | 1.03M | pub fn reserve(&mut self, additional: usize) { | 1335 | 1.03M | infallible(self.try_reserve(additional)) | 1336 | 1.03M | } |
<smallvec::SmallVec<[u8; 64]>>::reserve Line | Count | Source | 1334 | 1.72M | pub fn reserve(&mut self, additional: usize) { | 1335 | 1.72M | infallible(self.try_reserve(additional)) | 1336 | 1.72M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::reserve Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::reserve Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]>>::reserve <smallvec::SmallVec<[u8; 24]>>::reserve Line | Count | Source | 1334 | 4.94M | pub fn reserve(&mut self, additional: usize) { | 1335 | 4.94M | infallible(self.try_reserve(additional)) | 1336 | 4.94M | } |
<smallvec::SmallVec<[u8; 8]>>::reserve Line | Count | Source | 1334 | 26.4k | pub fn reserve(&mut self, additional: usize) { | 1335 | 26.4k | infallible(self.try_reserve(additional)) | 1336 | 26.4k | } |
Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]>>::reserve Unexecuted instantiation: <smallvec::SmallVec<[u32; 2]>>::reserve Unexecuted instantiation: <smallvec::SmallVec<_>>::reserve |
1337 | | |
1338 | | /// Internal method used to grow in push() and insert(), where we know |
1339 | | /// already we have to grow. |
1340 | | #[cold] |
1341 | 525k | fn reserve_one_unchecked(&mut self) { |
1342 | 525k | debug_assert_eq!(self.len(), self.capacity()); |
1343 | 525k | let new_cap = self |
1344 | 525k | .len() |
1345 | 525k | .checked_add(1) |
1346 | 525k | .and_then(usize::checked_next_power_of_two) |
1347 | 525k | .expect("capacity overflow"); |
1348 | 525k | infallible(self.try_grow(new_cap)) |
1349 | 525k | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::reserve_one_unchecked Line | Count | Source | 1341 | 1.48k | fn reserve_one_unchecked(&mut self) { | 1342 | 1.48k | debug_assert_eq!(self.len(), self.capacity()); | 1343 | 1.48k | let new_cap = self | 1344 | 1.48k | .len() | 1345 | 1.48k | .checked_add(1) | 1346 | 1.48k | .and_then(usize::checked_next_power_of_two) | 1347 | 1.48k | .expect("capacity overflow"); | 1348 | 1.48k | infallible(self.try_grow(new_cap)) | 1349 | 1.48k | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]>>::reserve_one_unchecked Line | Count | Source | 1341 | 3.08k | fn reserve_one_unchecked(&mut self) { | 1342 | 3.08k | debug_assert_eq!(self.len(), self.capacity()); | 1343 | 3.08k | let new_cap = self | 1344 | 3.08k | .len() | 1345 | 3.08k | .checked_add(1) | 1346 | 3.08k | .and_then(usize::checked_next_power_of_two) | 1347 | 3.08k | .expect("capacity overflow"); | 1348 | 3.08k | infallible(self.try_grow(new_cap)) | 1349 | 3.08k | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]>>::reserve_one_unchecked Line | Count | Source | 1341 | 4.72k | fn reserve_one_unchecked(&mut self) { | 1342 | 4.72k | debug_assert_eq!(self.len(), self.capacity()); | 1343 | 4.72k | let new_cap = self | 1344 | 4.72k | .len() | 1345 | 4.72k | .checked_add(1) | 1346 | 4.72k | .and_then(usize::checked_next_power_of_two) | 1347 | 4.72k | .expect("capacity overflow"); | 1348 | 4.72k | infallible(self.try_grow(new_cap)) | 1349 | 4.72k | } |
Unexecuted instantiation: <smallvec::SmallVec<[u8; 16]>>::reserve_one_unchecked Unexecuted instantiation: <smallvec::SmallVec<[u8; 64]>>::reserve_one_unchecked Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::reserve_one_unchecked Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::reserve_one_unchecked Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]>>::reserve_one_unchecked <smallvec::SmallVec<[u8; 24]>>::reserve_one_unchecked Line | Count | Source | 1341 | 516k | fn reserve_one_unchecked(&mut self) { | 1342 | 516k | debug_assert_eq!(self.len(), self.capacity()); | 1343 | 516k | let new_cap = self | 1344 | 516k | .len() | 1345 | 516k | .checked_add(1) | 1346 | 516k | .and_then(usize::checked_next_power_of_two) | 1347 | 516k | .expect("capacity overflow"); | 1348 | 516k | infallible(self.try_grow(new_cap)) | 1349 | 516k | } |
Unexecuted instantiation: <smallvec::SmallVec<[u8; 8]>>::reserve_one_unchecked Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]>>::reserve_one_unchecked <smallvec::SmallVec<[u32; 2]>>::reserve_one_unchecked Line | Count | Source | 1341 | 149 | fn reserve_one_unchecked(&mut self) { | 1342 | 149 | debug_assert_eq!(self.len(), self.capacity()); | 1343 | 149 | let new_cap = self | 1344 | 149 | .len() | 1345 | 149 | .checked_add(1) | 1346 | 149 | .and_then(usize::checked_next_power_of_two) | 1347 | 149 | .expect("capacity overflow"); | 1348 | 149 | infallible(self.try_grow(new_cap)) | 1349 | 149 | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::reserve_one_unchecked |
1350 | | |
1351 | | /// Reserve capacity for `additional` more elements to be inserted. |
1352 | | /// |
1353 | | /// May reserve more space to avoid frequent reallocations. |
1354 | 9.49M | pub fn try_reserve(&mut self, additional: usize) -> Result<(), CollectionAllocErr> { |
1355 | | // prefer triple_mut() even if triple() would work so that the optimizer |
1356 | | // removes duplicated calls to it from callers. |
1357 | 9.49M | let (_, &mut len, cap) = self.triple_mut(); |
1358 | 9.49M | if cap - len >= additional { |
1359 | 9.10M | return Ok(()); |
1360 | 387k | } |
1361 | 387k | let new_cap = len |
1362 | 387k | .checked_add(additional) |
1363 | 387k | .and_then(usize::checked_next_power_of_two) |
1364 | 387k | .ok_or(CollectionAllocErr::CapacityOverflow)?; |
1365 | 387k | self.try_grow(new_cap) |
1366 | 9.49M | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::try_reserve Line | Count | Source | 1354 | 3.04k | pub fn try_reserve(&mut self, additional: usize) -> Result<(), CollectionAllocErr> { | 1355 | | // prefer triple_mut() even if triple() would work so that the optimizer | 1356 | | // removes duplicated calls to it from callers. | 1357 | 3.04k | let (_, &mut len, cap) = self.triple_mut(); | 1358 | 3.04k | if cap - len >= additional { | 1359 | 3.04k | return Ok(()); | 1360 | 0 | } | 1361 | 0 | let new_cap = len | 1362 | 0 | .checked_add(additional) | 1363 | 0 | .and_then(usize::checked_next_power_of_two) | 1364 | 0 | .ok_or(CollectionAllocErr::CapacityOverflow)?; | 1365 | 0 | self.try_grow(new_cap) | 1366 | 3.04k | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]>>::try_reserve Line | Count | Source | 1354 | 868k | pub fn try_reserve(&mut self, additional: usize) -> Result<(), CollectionAllocErr> { | 1355 | | // prefer triple_mut() even if triple() would work so that the optimizer | 1356 | | // removes duplicated calls to it from callers. | 1357 | 868k | let (_, &mut len, cap) = self.triple_mut(); | 1358 | 868k | if cap - len >= additional { | 1359 | 868k | return Ok(()); | 1360 | 360 | } | 1361 | 360 | let new_cap = len | 1362 | 360 | .checked_add(additional) | 1363 | 360 | .and_then(usize::checked_next_power_of_two) | 1364 | 360 | .ok_or(CollectionAllocErr::CapacityOverflow)?; | 1365 | 360 | self.try_grow(new_cap) | 1366 | 868k | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]>>::try_reserve Line | Count | Source | 1354 | 884k | pub fn try_reserve(&mut self, additional: usize) -> Result<(), CollectionAllocErr> { | 1355 | | // prefer triple_mut() even if triple() would work so that the optimizer | 1356 | | // removes duplicated calls to it from callers. | 1357 | 884k | let (_, &mut len, cap) = self.triple_mut(); | 1358 | 884k | if cap - len >= additional { | 1359 | 884k | return Ok(()); | 1360 | 6 | } | 1361 | 6 | let new_cap = len | 1362 | 6 | .checked_add(additional) | 1363 | 6 | .and_then(usize::checked_next_power_of_two) | 1364 | 6 | .ok_or(CollectionAllocErr::CapacityOverflow)?; | 1365 | 6 | self.try_grow(new_cap) | 1366 | 884k | } |
<smallvec::SmallVec<[u8; 16]>>::try_reserve Line | Count | Source | 1354 | 1.03M | pub fn try_reserve(&mut self, additional: usize) -> Result<(), CollectionAllocErr> { | 1355 | | // prefer triple_mut() even if triple() would work so that the optimizer | 1356 | | // removes duplicated calls to it from callers. | 1357 | 1.03M | let (_, &mut len, cap) = self.triple_mut(); | 1358 | 1.03M | if cap - len >= additional { | 1359 | 837k | return Ok(()); | 1360 | 201k | } | 1361 | 201k | let new_cap = len | 1362 | 201k | .checked_add(additional) | 1363 | 201k | .and_then(usize::checked_next_power_of_two) | 1364 | 201k | .ok_or(CollectionAllocErr::CapacityOverflow)?; | 1365 | 201k | self.try_grow(new_cap) | 1366 | 1.03M | } |
<smallvec::SmallVec<[u8; 64]>>::try_reserve Line | Count | Source | 1354 | 1.72M | pub fn try_reserve(&mut self, additional: usize) -> Result<(), CollectionAllocErr> { | 1355 | | // prefer triple_mut() even if triple() would work so that the optimizer | 1356 | | // removes duplicated calls to it from callers. | 1357 | 1.72M | let (_, &mut len, cap) = self.triple_mut(); | 1358 | 1.72M | if cap - len >= additional { | 1359 | 1.63M | return Ok(()); | 1360 | 88.3k | } | 1361 | 88.3k | let new_cap = len | 1362 | 88.3k | .checked_add(additional) | 1363 | 88.3k | .and_then(usize::checked_next_power_of_two) | 1364 | 88.3k | .ok_or(CollectionAllocErr::CapacityOverflow)?; | 1365 | 88.3k | self.try_grow(new_cap) | 1366 | 1.72M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::try_reserve Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::try_reserve Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]>>::try_reserve <smallvec::SmallVec<[u8; 24]>>::try_reserve Line | Count | Source | 1354 | 4.94M | pub fn try_reserve(&mut self, additional: usize) -> Result<(), CollectionAllocErr> { | 1355 | | // prefer triple_mut() even if triple() would work so that the optimizer | 1356 | | // removes duplicated calls to it from callers. | 1357 | 4.94M | let (_, &mut len, cap) = self.triple_mut(); | 1358 | 4.94M | if cap - len >= additional { | 1359 | 4.84M | return Ok(()); | 1360 | 97.2k | } | 1361 | 97.2k | let new_cap = len | 1362 | 97.2k | .checked_add(additional) | 1363 | 97.2k | .and_then(usize::checked_next_power_of_two) | 1364 | 97.2k | .ok_or(CollectionAllocErr::CapacityOverflow)?; | 1365 | 97.2k | self.try_grow(new_cap) | 1366 | 4.94M | } |
<smallvec::SmallVec<[u8; 8]>>::try_reserve Line | Count | Source | 1354 | 26.4k | pub fn try_reserve(&mut self, additional: usize) -> Result<(), CollectionAllocErr> { | 1355 | | // prefer triple_mut() even if triple() would work so that the optimizer | 1356 | | // removes duplicated calls to it from callers. | 1357 | 26.4k | let (_, &mut len, cap) = self.triple_mut(); | 1358 | 26.4k | if cap - len >= additional { | 1359 | 26.4k | return Ok(()); | 1360 | 0 | } | 1361 | 0 | let new_cap = len | 1362 | 0 | .checked_add(additional) | 1363 | 0 | .and_then(usize::checked_next_power_of_two) | 1364 | 0 | .ok_or(CollectionAllocErr::CapacityOverflow)?; | 1365 | 0 | self.try_grow(new_cap) | 1366 | 26.4k | } |
Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]>>::try_reserve Unexecuted instantiation: <smallvec::SmallVec<[u32; 2]>>::try_reserve Unexecuted instantiation: <smallvec::SmallVec<_>>::try_reserve |
1367 | | |
1368 | | /// Reserve the minimum capacity for `additional` more elements to be |
1369 | | /// inserted. |
1370 | | /// |
1371 | | /// Panics if the new capacity overflows `usize`. |
1372 | 0 | pub fn reserve_exact(&mut self, additional: usize) { |
1373 | 0 | infallible(self.try_reserve_exact(additional)) |
1374 | 0 | } |
1375 | | |
1376 | | /// Reserve the minimum capacity for `additional` more elements to be |
1377 | | /// inserted. |
1378 | 0 | pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), CollectionAllocErr> { |
1379 | 0 | let (_, &mut len, cap) = self.triple_mut(); |
1380 | 0 | if cap - len >= additional { |
1381 | 0 | return Ok(()); |
1382 | 0 | } |
1383 | 0 | let new_cap = len |
1384 | 0 | .checked_add(additional) |
1385 | 0 | .ok_or(CollectionAllocErr::CapacityOverflow)?; |
1386 | 0 | self.try_grow(new_cap) |
1387 | 0 | } |
1388 | | |
1389 | | /// Shrink the capacity of the vector as much as possible. |
1390 | | /// |
1391 | | /// When possible, this will move data from an external heap buffer to the |
1392 | | /// vector's inline storage. |
1393 | 0 | pub fn shrink_to_fit(&mut self) { |
1394 | 0 | if !self.spilled() { |
1395 | 0 | return; |
1396 | 0 | } |
1397 | 0 | let len = self.len(); |
1398 | 0 | if self.inline_size() >= len { |
1399 | 0 | unsafe { |
1400 | 0 | let (ptr, len) = self.data.heap(); |
1401 | 0 | self.data = SmallVecData::empty(); |
1402 | 0 | ptr::copy_nonoverlapping(ptr.as_ptr(), self.data.inline_mut().as_ptr(), len); |
1403 | 0 | deallocate(ptr.0, self.capacity); |
1404 | 0 | self.capacity = len; |
1405 | 0 | } |
1406 | 0 | } else if self.capacity() > len { |
1407 | 0 | self.grow(len); |
1408 | 0 | } |
1409 | 0 | } |
1410 | | |
1411 | | /// Shorten the vector, keeping the first `len` elements and dropping the |
1412 | | /// rest. |
1413 | | /// |
1414 | | /// If `len` is greater than or equal to the vector's current length, this |
1415 | | /// has no effect. |
1416 | | /// |
1417 | | /// This does not re-allocate. If you want the vector's capacity to shrink, |
1418 | | /// call `shrink_to_fit` after truncating. |
1419 | 0 | pub fn truncate(&mut self, len: usize) { |
1420 | | unsafe { |
1421 | 0 | let (ptr, len_ptr, _) = self.triple_mut(); |
1422 | 0 | let ptr = ptr.as_ptr(); |
1423 | 0 | while len < *len_ptr { |
1424 | 0 | let last_index = *len_ptr - 1; |
1425 | 0 | *len_ptr = last_index; |
1426 | 0 | ptr::drop_in_place(ptr.add(last_index)); |
1427 | 0 | } |
1428 | | } |
1429 | 0 | } Unexecuted instantiation: <smallvec::SmallVec<[u8; 64]>>::truncate Unexecuted instantiation: <smallvec::SmallVec<_>>::truncate |
1430 | | |
1431 | | /// Extracts a slice containing the entire vector. |
1432 | | /// |
1433 | | /// Equivalent to `&s[..]`. |
1434 | 13.0M | pub fn as_slice(&self) -> &[A::Item] { |
1435 | 13.0M | self |
1436 | 13.0M | } <smallvec::SmallVec<[exr::meta::header::Header; 3]>>::as_slice Line | Count | Source | 1434 | 872k | pub fn as_slice(&self) -> &[A::Item] { | 1435 | 872k | self | 1436 | 872k | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]>>::as_slice Line | Count | Source | 1434 | 884k | pub fn as_slice(&self) -> &[A::Item] { | 1435 | 884k | self | 1436 | 884k | } |
<smallvec::SmallVec<[u8; 16]>>::as_slice Line | Count | Source | 1434 | 177k | pub fn as_slice(&self) -> &[A::Item] { | 1435 | 177k | self | 1436 | 177k | } |
<smallvec::SmallVec<[u8; 64]>>::as_slice Line | Count | Source | 1434 | 1.94M | pub fn as_slice(&self) -> &[A::Item] { | 1435 | 1.94M | self | 1436 | 1.94M | } |
<smallvec::SmallVec<[u8; 24]>>::as_slice Line | Count | Source | 1434 | 9.13M | pub fn as_slice(&self) -> &[A::Item] { | 1435 | 9.13M | self | 1436 | 9.13M | } |
Unexecuted instantiation: <smallvec::SmallVec<[u32; 2]>>::as_slice Unexecuted instantiation: <smallvec::SmallVec<_>>::as_slice |
1437 | | |
1438 | | /// Extracts a mutable slice of the entire vector. |
1439 | | /// |
1440 | | /// Equivalent to `&mut s[..]`. |
1441 | 0 | pub fn as_mut_slice(&mut self) -> &mut [A::Item] { |
1442 | 0 | self |
1443 | 0 | } |
1444 | | |
1445 | | /// Remove the element at position `index`, replacing it with the last |
1446 | | /// element. |
1447 | | /// |
1448 | | /// This does not preserve ordering, but is O(1). |
1449 | | /// |
1450 | | /// Panics if `index` is out of bounds. |
1451 | | #[inline] |
1452 | 0 | pub fn swap_remove(&mut self, index: usize) -> A::Item { |
1453 | 0 | let len = self.len(); |
1454 | 0 | self.swap(len - 1, index); |
1455 | 0 | self.pop() |
1456 | 0 | .unwrap_or_else(|| unsafe { unreachable_unchecked() }) |
1457 | 0 | } |
1458 | | |
1459 | | /// Remove all elements from the vector. |
1460 | | #[inline] |
1461 | 0 | pub fn clear(&mut self) { |
1462 | 0 | self.truncate(0); |
1463 | 0 | } |
1464 | | |
1465 | | /// Remove and return the element at position `index`, shifting all elements |
1466 | | /// after it to the left. |
1467 | | /// |
1468 | | /// Panics if `index` is out of bounds. |
1469 | 0 | pub fn remove(&mut self, index: usize) -> A::Item { |
1470 | | unsafe { |
1471 | 0 | let (ptr, len_ptr, _) = self.triple_mut(); |
1472 | 0 | let len = *len_ptr; |
1473 | 0 | assert!(index < len); |
1474 | 0 | *len_ptr = len - 1; |
1475 | 0 | let ptr = ptr.as_ptr().add(index); |
1476 | 0 | let item = ptr::read(ptr); |
1477 | 0 | ptr::copy(ptr.add(1), ptr, len - index - 1); |
1478 | 0 | item |
1479 | | } |
1480 | 0 | } |
1481 | | |
1482 | | /// Insert an element at position `index`, shifting all elements after it to |
1483 | | /// the right. |
1484 | | /// |
1485 | | /// Panics if `index > len`. |
1486 | 0 | pub fn insert(&mut self, index: usize, element: A::Item) { |
1487 | | unsafe { |
1488 | 0 | let (mut ptr, mut len_ptr, cap) = self.triple_mut(); |
1489 | 0 | if *len_ptr == cap { |
1490 | 0 | self.reserve_one_unchecked(); |
1491 | 0 | let (heap_ptr, heap_len_ptr) = self.data.heap_mut(); |
1492 | 0 | ptr = heap_ptr; |
1493 | 0 | len_ptr = heap_len_ptr; |
1494 | 0 | } |
1495 | 0 | let mut ptr = ptr.as_ptr(); |
1496 | 0 | let len = *len_ptr; |
1497 | 0 | if index > len { |
1498 | 0 | panic!("index exceeds length"); |
1499 | 0 | } |
1500 | | // SAFETY: add is UB if index > len, but we panicked first |
1501 | 0 | ptr = ptr.add(index); |
1502 | 0 | if index < len { |
1503 | 0 | // Shift element to the right of `index`. |
1504 | 0 | ptr::copy(ptr, ptr.add(1), len - index); |
1505 | 0 | } |
1506 | 0 | *len_ptr = len + 1; |
1507 | 0 | ptr::write(ptr, element); |
1508 | | } |
1509 | 0 | } |
1510 | | |
1511 | | /// Insert multiple elements at position `index`, shifting all following |
1512 | | /// elements toward the back. |
1513 | 0 | pub fn insert_many<I: IntoIterator<Item = A::Item>>(&mut self, index: usize, iterable: I) { |
1514 | 0 | let mut iter = iterable.into_iter(); |
1515 | 0 | if index == self.len() { |
1516 | 0 | return self.extend(iter); |
1517 | 0 | } |
1518 | | |
1519 | 0 | let (lower_size_bound, _) = iter.size_hint(); |
1520 | | #[allow(deprecated)] |
1521 | | { |
1522 | 0 | assert!(lower_size_bound <= core::isize::MAX as usize) |
1523 | | } // Ensure offset is indexable |
1524 | 0 | assert!(index + lower_size_bound >= index); // Protect against overflow |
1525 | | |
1526 | 0 | let mut num_added = 0; |
1527 | 0 | let old_len = self.len(); |
1528 | 0 | assert!(index <= old_len); |
1529 | | |
1530 | | unsafe { |
1531 | | // Reserve space for `lower_size_bound` elements. |
1532 | 0 | self.reserve(lower_size_bound); |
1533 | 0 | let start = self.as_mut_ptr(); |
1534 | 0 | let ptr = start.add(index); |
1535 | | |
1536 | | // Move the trailing elements. |
1537 | 0 | ptr::copy(ptr, ptr.add(lower_size_bound), old_len - index); |
1538 | | |
1539 | | // In case the iterator panics, don't double-drop the items we just |
1540 | | // copied above. |
1541 | 0 | self.set_len(0); |
1542 | 0 | let mut guard = DropOnPanic { |
1543 | 0 | start, |
1544 | 0 | skip: index..(index + lower_size_bound), |
1545 | 0 | len: old_len + lower_size_bound, |
1546 | 0 | }; |
1547 | | |
1548 | | // The set_len above invalidates the previous pointers, so we must |
1549 | | // re-create them. |
1550 | 0 | let start = self.as_mut_ptr(); |
1551 | 0 | let ptr = start.add(index); |
1552 | | |
1553 | 0 | while num_added < lower_size_bound { |
1554 | 0 | let element = match iter.next() { |
1555 | 0 | Some(x) => x, |
1556 | 0 | None => break, |
1557 | | }; |
1558 | 0 | let cur = ptr.add(num_added); |
1559 | 0 | ptr::write(cur, element); |
1560 | 0 | guard.skip.start += 1; |
1561 | 0 | num_added += 1; |
1562 | | } |
1563 | | |
1564 | 0 | if num_added < lower_size_bound { |
1565 | 0 | // Iterator provided fewer elements than the hint. Move the tail |
1566 | 0 | // backward. |
1567 | 0 | ptr::copy( |
1568 | 0 | ptr.add(lower_size_bound), |
1569 | 0 | ptr.add(num_added), |
1570 | 0 | old_len - index, |
1571 | 0 | ); |
1572 | 0 | } |
1573 | | // There are no more duplicate or uninitialized slots, so the guard |
1574 | | // is not needed. |
1575 | 0 | self.set_len(old_len + num_added); |
1576 | 0 | mem::forget(guard); |
1577 | | } |
1578 | | |
1579 | | // Insert any remaining elements one-by-one. |
1580 | 0 | for element in iter { |
1581 | 0 | self.insert(index + num_added, element); |
1582 | 0 | num_added += 1; |
1583 | 0 | } |
1584 | | |
1585 | | struct DropOnPanic<T> { |
1586 | | start: *mut T, |
1587 | | skip: Range<usize>, // Space we copied-out-of, but haven't written-to yet. |
1588 | | len: usize, |
1589 | | } |
1590 | | |
1591 | | impl<T> Drop for DropOnPanic<T> { |
1592 | 0 | fn drop(&mut self) { |
1593 | 0 | for i in 0..self.len { |
1594 | 0 | if !self.skip.contains(&i) { |
1595 | 0 | unsafe { |
1596 | 0 | ptr::drop_in_place(self.start.add(i)); |
1597 | 0 | } |
1598 | 0 | } |
1599 | | } |
1600 | 0 | } |
1601 | | } |
1602 | 0 | } |
1603 | | |
1604 | | /// Convert a `SmallVec` to a `Vec`, without reallocating if the `SmallVec` |
1605 | | /// has already spilled onto the heap. |
1606 | 0 | pub fn into_vec(mut self) -> Vec<A::Item> { |
1607 | 0 | if self.spilled() { |
1608 | | unsafe { |
1609 | 0 | let (ptr, &mut len) = self.data.heap_mut(); |
1610 | 0 | let v = Vec::from_raw_parts(ptr.as_ptr(), len, self.capacity); |
1611 | 0 | mem::forget(self); |
1612 | 0 | v |
1613 | | } |
1614 | | } else { |
1615 | 0 | self.into_iter().collect() |
1616 | | } |
1617 | 0 | } |
1618 | | |
1619 | | /// Converts a `SmallVec` into a `Box<[T]>` without reallocating if the |
1620 | | /// `SmallVec` has already spilled onto the heap. |
1621 | | /// |
1622 | | /// Note that this will drop any excess capacity. |
1623 | 0 | pub fn into_boxed_slice(self) -> Box<[A::Item]> { |
1624 | 0 | self.into_vec().into_boxed_slice() |
1625 | 0 | } |
1626 | | |
1627 | | /// Convert the `SmallVec` into an `A` if possible. Otherwise return |
1628 | | /// `Err(Self)`. |
1629 | | /// |
1630 | | /// This method returns `Err(Self)` if the `SmallVec` is too short (and the |
1631 | | /// `A` contains uninitialized elements), or if the `SmallVec` is too |
1632 | | /// long (and all the elements were spilled to the heap). |
1633 | 26.4k | pub fn into_inner(self) -> Result<A, Self> { |
1634 | 26.4k | if self.spilled() || self.len() != A::size() { |
1635 | | // Note: A::size, not Self::inline_capacity |
1636 | 0 | Err(self) |
1637 | | } else { |
1638 | | unsafe { |
1639 | 26.4k | let data = ptr::read(&self.data); |
1640 | 26.4k | mem::forget(self); |
1641 | 26.4k | Ok(data.into_inline().assume_init()) |
1642 | | } |
1643 | | } |
1644 | 26.4k | } <smallvec::SmallVec<[u8; 8]>>::into_inner Line | Count | Source | 1633 | 26.4k | pub fn into_inner(self) -> Result<A, Self> { | 1634 | 26.4k | if self.spilled() || self.len() != A::size() { | 1635 | | // Note: A::size, not Self::inline_capacity | 1636 | 0 | Err(self) | 1637 | | } else { | 1638 | | unsafe { | 1639 | 26.4k | let data = ptr::read(&self.data); | 1640 | 26.4k | mem::forget(self); | 1641 | 26.4k | Ok(data.into_inline().assume_init()) | 1642 | | } | 1643 | | } | 1644 | 26.4k | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::into_inner |
1645 | | |
1646 | | /// Retains only the elements specified by the predicate. |
1647 | | /// |
1648 | | /// In other words, remove all elements `e` such that `f(&e)` returns |
1649 | | /// `false`. This method operates in place and preserves the order of |
1650 | | /// the retained elements. |
1651 | 0 | pub fn retain<F: FnMut(&mut A::Item) -> bool>(&mut self, mut f: F) { |
1652 | 0 | let original_len = self.len(); |
1653 | | |
1654 | 0 | if original_len == 0 { |
1655 | | // Empty case: explicit return allows better optimization, vs |
1656 | | // letting compiler infer it |
1657 | 0 | return; |
1658 | 0 | } |
1659 | | |
1660 | | // Vec: [Kept, Kept, Hole, Hole, Hole, Hole, Unchecked, Unchecked] |
1661 | | // | ^- write ^- read | |
1662 | | // |<- original_len ->| |
1663 | | // Kept: Elements which predicate returns true on. |
1664 | | // Hole: Moved or dropped element slot. |
1665 | | // Unchecked: Unchecked valid elements. |
1666 | | // |
1667 | | // This drop guard will be invoked when predicate or `drop` of element |
1668 | | // panicked. It shifts unchecked elements to cover holes and |
1669 | | // `set_len` to the correct length. In cases when predicate and |
1670 | | // `drop` never panic, it will be optimized out. |
1671 | | struct PanicGuard<'a, A: Array> { |
1672 | | v: &'a mut SmallVec<A>, |
1673 | | read: usize, |
1674 | | write: usize, |
1675 | | original_len: usize, |
1676 | | } |
1677 | | |
1678 | | impl<A: Array> Drop for PanicGuard<'_, A> { |
1679 | | #[cold] |
1680 | 0 | fn drop(&mut self) { |
1681 | 0 | let remaining = self.original_len - self.read; |
1682 | | // SAFETY: Trailing unchecked items must be valid since we never |
1683 | | // touch them. |
1684 | 0 | unsafe { |
1685 | 0 | let ptr = self.v.as_mut_ptr(); |
1686 | 0 | ptr::copy(ptr.add(self.read), ptr.add(self.write), remaining); |
1687 | 0 | } |
1688 | | // SAFETY: After filling holes, all items are in contiguous |
1689 | | // memory. |
1690 | 0 | unsafe { |
1691 | 0 | self.v.set_len(self.write + remaining); |
1692 | 0 | } |
1693 | 0 | } |
1694 | | } |
1695 | | |
1696 | 0 | let mut read = 0; |
1697 | | loop { |
1698 | | // SAFETY: read < original_len |
1699 | 0 | let cur = unsafe { self.get_unchecked_mut(read) }; |
1700 | 0 | if !f(cur) { |
1701 | 0 | break; |
1702 | 0 | } |
1703 | 0 | read += 1; |
1704 | 0 | if read == original_len { |
1705 | | // All elements are kept, return early. |
1706 | 0 | return; |
1707 | 0 | } |
1708 | | } |
1709 | | |
1710 | | // Critical section starts here and at least one element is going to be |
1711 | | // removed. Advance `g.read` early to avoid double drop if |
1712 | | // `drop_in_place` panicked. |
1713 | 0 | let mut g = PanicGuard { |
1714 | 0 | v: self, |
1715 | 0 | read: read + 1, |
1716 | 0 | write: read, |
1717 | 0 | original_len, |
1718 | 0 | }; |
1719 | | // SAFETY: previous `read` is always less than original_len. |
1720 | 0 | unsafe { ptr::drop_in_place(g.v.as_mut_ptr().add(read)) } |
1721 | | |
1722 | 0 | let ptr = g.v.as_mut_ptr(); |
1723 | 0 | while g.read < g.original_len { |
1724 | | // SAFETY: `read` is always less than original_len. |
1725 | 0 | let cur = unsafe { &mut *ptr.add(g.read) }; |
1726 | 0 | if !f(cur) { |
1727 | 0 | // Advance `read` early to avoid double drop if `drop_in_place` |
1728 | 0 | // panicked. |
1729 | 0 | g.read += 1; |
1730 | 0 | // SAFETY: We never touch this element again after dropped. |
1731 | 0 | unsafe { ptr::drop_in_place(cur) }; |
1732 | 0 | } else { |
1733 | 0 | // SAFETY: `read` > `write`, so the slots don't overlap. |
1734 | 0 | // We use copy for move, and never touch the source element |
1735 | 0 | // again. |
1736 | 0 | unsafe { |
1737 | 0 | let hole = ptr.add(g.write); |
1738 | 0 | ptr::copy_nonoverlapping(cur, hole, 1); |
1739 | 0 | } |
1740 | 0 | g.write += 1; |
1741 | 0 | g.read += 1; |
1742 | 0 | } |
1743 | | } |
1744 | | |
1745 | | // We are leaving the critical section and no panic happened, |
1746 | | // Commit the length change and forget the guard. |
1747 | | // SAFETY: `write` is always less than or equal to original_len. |
1748 | 0 | unsafe { g.v.set_len(g.write) }; |
1749 | 0 | core::mem::forget(g); |
1750 | 0 | } |
1751 | | |
1752 | | /// Retains only the elements specified by the predicate. |
1753 | | /// |
1754 | | /// This method is identical in behaviour to [`SmallVec::retain`]; it is |
1755 | | /// included only to maintain api-compatibility with `std::Vec`, where |
1756 | | /// the methods are separate for historical reasons. |
1757 | 0 | pub fn retain_mut<F: FnMut(&mut A::Item) -> bool>(&mut self, f: F) { |
1758 | 0 | self.retain(f) |
1759 | 0 | } |
1760 | | |
1761 | | /// Removes consecutive duplicate elements. |
1762 | 0 | pub fn dedup(&mut self) |
1763 | 0 | where |
1764 | 0 | A::Item: PartialEq<A::Item>, |
1765 | | { |
1766 | 0 | self.dedup_by(|a, b| a == b); |
1767 | 0 | } |
1768 | | |
1769 | | /// Removes consecutive duplicate elements using the given equality |
1770 | | /// relation. |
1771 | 0 | pub fn dedup_by<F>(&mut self, mut same_bucket: F) |
1772 | 0 | where |
1773 | 0 | F: FnMut(&mut A::Item, &mut A::Item) -> bool, |
1774 | | { |
1775 | | // See the implementation of Vec::dedup_by in the |
1776 | | // standard library for an explanation of this algorithm. |
1777 | 0 | let len = self.len(); |
1778 | 0 | if len <= 1 { |
1779 | 0 | return; |
1780 | 0 | } |
1781 | | |
1782 | 0 | let ptr = self.as_mut_ptr(); |
1783 | 0 | let mut w: usize = 1; |
1784 | | |
1785 | | unsafe { |
1786 | 0 | for r in 1..len { |
1787 | 0 | let p_r = ptr.add(r); |
1788 | 0 | let p_wm1 = ptr.add(w - 1); |
1789 | 0 | if !same_bucket(&mut *p_r, &mut *p_wm1) { |
1790 | 0 | if r != w { |
1791 | 0 | let p_w = p_wm1.add(1); |
1792 | 0 | mem::swap(&mut *p_r, &mut *p_w); |
1793 | 0 | } |
1794 | 0 | w += 1; |
1795 | 0 | } |
1796 | | } |
1797 | | } |
1798 | | |
1799 | 0 | self.truncate(w); |
1800 | 0 | } |
1801 | | |
1802 | | /// Removes consecutive elements that map to the same key. |
1803 | 0 | pub fn dedup_by_key<F, K>(&mut self, mut key: F) |
1804 | 0 | where |
1805 | 0 | F: FnMut(&mut A::Item) -> K, |
1806 | 0 | K: PartialEq<K>, |
1807 | | { |
1808 | 0 | self.dedup_by(|a, b| key(a) == key(b)); |
1809 | 0 | } |
1810 | | |
1811 | | /// Resizes the `SmallVec` in-place so that `len` is equal to `new_len`. |
1812 | | /// |
1813 | | /// If `new_len` is greater than `len`, the `SmallVec` is extended by the |
1814 | | /// difference, with each additional slot filled with the result of |
1815 | | /// calling the closure `f`. The return values from `f` will end up in |
1816 | | /// the `SmallVec` in the order they have been generated. |
1817 | | /// |
1818 | | /// If `new_len` is less than `len`, the `SmallVec` is simply truncated. |
1819 | | /// |
1820 | | /// This method uses a closure to create new values on every push. If you'd |
1821 | | /// rather `Clone` a given value, use `resize`. If you want to use the |
1822 | | /// `Default` trait to generate values, you can pass |
1823 | | /// `Default::default()` as the second argument. |
1824 | | /// |
1825 | | /// Added for `std::vec::Vec` compatibility (added in Rust 1.33.0) |
1826 | | /// |
1827 | | /// ``` |
1828 | | /// # use smallvec::{smallvec, SmallVec}; |
1829 | | /// let mut vec: SmallVec<[_; 4]> = smallvec![1, 2, 3]; |
1830 | | /// vec.resize_with(5, Default::default); |
1831 | | /// assert_eq!(&*vec, &[1, 2, 3, 0, 0]); |
1832 | | /// |
1833 | | /// let mut vec: SmallVec<[_; 4]> = smallvec![]; |
1834 | | /// let mut p = 1; |
1835 | | /// vec.resize_with(4, || { |
1836 | | /// p *= 2; |
1837 | | /// p |
1838 | | /// }); |
1839 | | /// assert_eq!(&*vec, &[2, 4, 8, 16]); |
1840 | | /// ``` |
1841 | 0 | pub fn resize_with<F>(&mut self, new_len: usize, f: F) |
1842 | 0 | where |
1843 | 0 | F: FnMut() -> A::Item, |
1844 | | { |
1845 | 0 | let old_len = self.len(); |
1846 | 0 | if old_len < new_len { |
1847 | 0 | let mut f = f; |
1848 | 0 | let additional = new_len - old_len; |
1849 | 0 | self.reserve(additional); |
1850 | 0 | for _ in 0..additional { |
1851 | 0 | self.push(f()); |
1852 | 0 | } |
1853 | 0 | } else if old_len > new_len { |
1854 | 0 | self.truncate(new_len); |
1855 | 0 | } |
1856 | 0 | } |
1857 | | |
1858 | | /// Creates a `SmallVec` directly from the raw components of another |
1859 | | /// `SmallVec`. |
1860 | | /// |
1861 | | /// # Safety |
1862 | | /// |
1863 | | /// This is highly unsafe, due to the number of invariants that aren't |
1864 | | /// checked: |
1865 | | /// |
1866 | | /// * `ptr` needs to have been previously allocated via `SmallVec` for its |
1867 | | /// spilled storage (at least, it's highly likely to be incorrect if it |
1868 | | /// wasn't). |
1869 | | /// * `ptr`'s `A::Item` type needs to be the same size and alignment that it |
1870 | | /// was allocated with |
1871 | | /// * `length` needs to be less than or equal to `capacity`. |
1872 | | /// * `capacity` needs to be the capacity that the pointer was allocated |
1873 | | /// with. |
1874 | | /// |
1875 | | /// Violating these may cause problems like corrupting the allocator's |
1876 | | /// internal data structures. |
1877 | | /// |
1878 | | /// Additionally, `capacity` must be greater than the amount of inline |
1879 | | /// storage `A` has; that is, the new `SmallVec` must need to spill over |
1880 | | /// into heap allocated storage. This condition is asserted against. |
1881 | | /// |
1882 | | /// The ownership of `ptr` is effectively transferred to the |
1883 | | /// `SmallVec` which may then deallocate, reallocate or change the |
1884 | | /// contents of memory pointed to by the pointer at will. Ensure |
1885 | | /// that nothing else uses the pointer after calling this |
1886 | | /// function. |
1887 | | /// |
1888 | | /// # Examples |
1889 | | /// |
1890 | | /// ``` |
1891 | | /// # use smallvec::{smallvec, SmallVec}; |
1892 | | /// use std::mem; |
1893 | | /// use std::ptr; |
1894 | | /// |
1895 | | /// fn main() { |
1896 | | /// let mut v: SmallVec<[_; 1]> = smallvec![1, 2, 3]; |
1897 | | /// |
1898 | | /// // Pull out the important parts of `v`. |
1899 | | /// let p = v.as_mut_ptr(); |
1900 | | /// let len = v.len(); |
1901 | | /// let cap = v.capacity(); |
1902 | | /// let spilled = v.spilled(); |
1903 | | /// |
1904 | | /// unsafe { |
1905 | | /// // Forget all about `v`. The heap allocation that stored the |
1906 | | /// // three values won't be deallocated. |
1907 | | /// mem::forget(v); |
1908 | | /// |
1909 | | /// // Overwrite memory with [4, 5, 6]. |
1910 | | /// // |
1911 | | /// // This is only safe if `spilled` is true! Otherwise, we are |
1912 | | /// // writing into the old `SmallVec`'s inline storage on the |
1913 | | /// // stack. |
1914 | | /// assert!(spilled); |
1915 | | /// for i in 0..len { |
1916 | | /// ptr::write(p.add(i), 4 + i); |
1917 | | /// } |
1918 | | /// |
1919 | | /// // Put everything back together into a SmallVec with a different |
1920 | | /// // amount of inline storage, but which is still less than `cap`. |
1921 | | /// let rebuilt = SmallVec::<[_; 2]>::from_raw_parts(p, len, cap); |
1922 | | /// assert_eq!(&*rebuilt, &[4, 5, 6]); |
1923 | | /// } |
1924 | | /// } |
1925 | | #[inline] |
1926 | 0 | pub unsafe fn from_raw_parts(ptr: *mut A::Item, length: usize, capacity: usize) -> SmallVec<A> { |
1927 | | // SAFETY: We require caller to provide same ptr as we alloc |
1928 | | // and we never alloc null pointer. |
1929 | 0 | let ptr = unsafe { |
1930 | 0 | debug_assert!(!ptr.is_null(), "Called `from_raw_parts` with null pointer."); |
1931 | 0 | NonNull::new_unchecked(ptr) |
1932 | | }; |
1933 | 0 | assert!(capacity > Self::inline_capacity()); |
1934 | 0 | SmallVec { |
1935 | 0 | capacity, |
1936 | 0 | data: SmallVecData::from_heap(ptr, length), |
1937 | 0 | _marker: PhantomData, |
1938 | 0 | } |
1939 | 0 | } |
1940 | | |
1941 | | /// Returns a raw pointer to the vector's buffer. |
1942 | 95 | pub fn as_ptr(&self) -> *const A::Item { |
1943 | | // We shadow the slice method of the same name to avoid going through |
1944 | | // `deref`, which creates an intermediate reference that may place |
1945 | | // additional safety constraints on the contents of the slice. |
1946 | 95 | self.triple().0.as_ptr() |
1947 | 95 | } Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>>::as_ptr Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]>>::as_ptr Unexecuted instantiation: <smallvec::SmallVec<_>>::as_ptr Unexecuted instantiation: <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::as_ptr <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]>>::as_ptr Line | Count | Source | 1942 | 95 | pub fn as_ptr(&self) -> *const A::Item { | 1943 | | // We shadow the slice method of the same name to avoid going through | 1944 | | // `deref`, which creates an intermediate reference that may place | 1945 | | // additional safety constraints on the contents of the slice. | 1946 | 95 | self.triple().0.as_ptr() | 1947 | 95 | } |
|
1948 | | |
1949 | | /// Returns a raw mutable pointer to the vector's buffer. |
1950 | 0 | pub fn as_mut_ptr(&mut self) -> *mut A::Item { |
1951 | | // We shadow the slice method of the same name to avoid going through |
1952 | | // `deref_mut`, which creates an intermediate reference that may place |
1953 | | // additional safety constraints on the contents of the slice. |
1954 | 0 | self.triple_mut().0.as_ptr() |
1955 | 0 | } |
1956 | | } |
1957 | | |
1958 | | impl<A: Array> SmallVec<A> |
1959 | | where |
1960 | | A::Item: Copy, |
1961 | | { |
1962 | | /// Copy the elements from a slice into a new `SmallVec`. |
1963 | | /// |
1964 | | /// For slices of `Copy` types, this is more efficient than |
1965 | | /// `SmallVec::from(slice)`. |
1966 | 207k | pub fn from_slice(slice: &[A::Item]) -> Self { |
1967 | 207k | let len = slice.len(); |
1968 | 207k | if len <= Self::inline_capacity() { |
1969 | 207k | SmallVec { |
1970 | 207k | capacity: len, |
1971 | 207k | data: SmallVecData::from_inline(unsafe { |
1972 | 207k | let mut data: MaybeUninit<A> = MaybeUninit::uninit(); |
1973 | 207k | ptr::copy_nonoverlapping( |
1974 | 207k | slice.as_ptr(), |
1975 | 207k | data.as_mut_ptr() as *mut A::Item, |
1976 | 207k | len, |
1977 | 207k | ); |
1978 | 207k | data |
1979 | 207k | }), |
1980 | 207k | _marker: PhantomData, |
1981 | 207k | } |
1982 | | } else { |
1983 | 0 | let mut b = slice.to_vec(); |
1984 | 0 | let cap = b.capacity(); |
1985 | 0 | let ptr = NonNull::new(b.as_mut_ptr()).expect("Vec always contain non null pointers."); |
1986 | 0 | mem::forget(b); |
1987 | 0 | SmallVec { |
1988 | 0 | capacity: cap, |
1989 | 0 | data: SmallVecData::from_heap(ptr, len), |
1990 | 0 | _marker: PhantomData, |
1991 | 0 | } |
1992 | | } |
1993 | 207k | } <smallvec::SmallVec<[u8; 24]>>::from_slice Line | Count | Source | 1966 | 207k | pub fn from_slice(slice: &[A::Item]) -> Self { | 1967 | 207k | let len = slice.len(); | 1968 | 207k | if len <= Self::inline_capacity() { | 1969 | 207k | SmallVec { | 1970 | 207k | capacity: len, | 1971 | 207k | data: SmallVecData::from_inline(unsafe { | 1972 | 207k | let mut data: MaybeUninit<A> = MaybeUninit::uninit(); | 1973 | 207k | ptr::copy_nonoverlapping( | 1974 | 207k | slice.as_ptr(), | 1975 | 207k | data.as_mut_ptr() as *mut A::Item, | 1976 | 207k | len, | 1977 | 207k | ); | 1978 | 207k | data | 1979 | 207k | }), | 1980 | 207k | _marker: PhantomData, | 1981 | 207k | } | 1982 | | } else { | 1983 | 0 | let mut b = slice.to_vec(); | 1984 | 0 | let cap = b.capacity(); | 1985 | 0 | let ptr = NonNull::new(b.as_mut_ptr()).expect("Vec always contain non null pointers."); | 1986 | 0 | mem::forget(b); | 1987 | 0 | SmallVec { | 1988 | 0 | capacity: cap, | 1989 | 0 | data: SmallVecData::from_heap(ptr, len), | 1990 | 0 | _marker: PhantomData, | 1991 | 0 | } | 1992 | | } | 1993 | 207k | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::from_slice |
1994 | | |
1995 | | /// Copy elements from a slice into the vector at position `index`, shifting |
1996 | | /// any following elements toward the back. |
1997 | | /// |
1998 | | /// For slices of `Copy` types, this is more efficient than `insert`. |
1999 | | #[inline] |
2000 | 0 | pub fn insert_from_slice(&mut self, index: usize, slice: &[A::Item]) { |
2001 | 0 | self.reserve(slice.len()); |
2002 | | |
2003 | 0 | let len = self.len(); |
2004 | 0 | assert!(index <= len); |
2005 | | |
2006 | 0 | unsafe { |
2007 | 0 | let slice_ptr = slice.as_ptr(); |
2008 | 0 | let ptr = self.as_mut_ptr().add(index); |
2009 | 0 | ptr::copy(ptr, ptr.add(slice.len()), len - index); |
2010 | 0 | ptr::copy_nonoverlapping(slice_ptr, ptr, slice.len()); |
2011 | 0 | self.set_len(len + slice.len()); |
2012 | 0 | } |
2013 | 0 | } |
2014 | | |
2015 | | /// Copy elements from a slice and append them to the vector. |
2016 | | /// |
2017 | | /// For slices of `Copy` types, this is more efficient than `extend`. |
2018 | | #[inline] |
2019 | 0 | pub fn extend_from_slice(&mut self, slice: &[A::Item]) { |
2020 | 0 | let len = self.len(); |
2021 | 0 | self.insert_from_slice(len, slice); |
2022 | 0 | } |
2023 | | } |
2024 | | |
2025 | | impl<A: Array> SmallVec<A> |
2026 | | where |
2027 | | A::Item: Clone, |
2028 | | { |
2029 | | /// Resizes the vector so that its length is equal to `len`. |
2030 | | /// |
2031 | | /// If `len` is less than the current length, the vector simply truncated. |
2032 | | /// |
2033 | | /// If `len` is greater than the current length, `value` is appended to the |
2034 | | /// vector until its length equals `len`. |
2035 | 1.72M | pub fn resize(&mut self, len: usize, value: A::Item) { |
2036 | 1.72M | let old_len = self.len(); |
2037 | | |
2038 | 1.72M | if len > old_len { |
2039 | 1.72M | self.extend(repeat(value).take(len - old_len)); |
2040 | 1.72M | } else { |
2041 | 0 | self.truncate(len); |
2042 | 0 | } |
2043 | 1.72M | } <smallvec::SmallVec<[u8; 64]>>::resize Line | Count | Source | 2035 | 1.72M | pub fn resize(&mut self, len: usize, value: A::Item) { | 2036 | 1.72M | let old_len = self.len(); | 2037 | | | 2038 | 1.72M | if len > old_len { | 2039 | 1.72M | self.extend(repeat(value).take(len - old_len)); | 2040 | 1.72M | } else { | 2041 | 0 | self.truncate(len); | 2042 | 0 | } | 2043 | 1.72M | } |
Unexecuted instantiation: <smallvec::SmallVec<_>>::resize |
2044 | | |
2045 | | /// Creates a `SmallVec` with `n` copies of `elem`. |
2046 | | /// ``` |
2047 | | /// use smallvec::SmallVec; |
2048 | | /// |
2049 | | /// let v = SmallVec::<[char; 128]>::from_elem('d', 2); |
2050 | | /// assert_eq!(v, SmallVec::from_buf(['d', 'd'])); |
2051 | | /// ``` |
2052 | 0 | pub fn from_elem(elem: A::Item, n: usize) -> Self { |
2053 | 0 | if n > Self::inline_capacity() { |
2054 | 0 | vec![elem; n].into() |
2055 | | } else { |
2056 | 0 | let mut v = SmallVec::<A>::new(); |
2057 | | unsafe { |
2058 | 0 | let (ptr, len_ptr, _) = v.triple_mut(); |
2059 | 0 | let ptr = ptr.as_ptr(); |
2060 | 0 | let mut local_len = SetLenOnDrop::new(len_ptr); |
2061 | | |
2062 | 0 | for i in 0..n { |
2063 | 0 | ::core::ptr::write(ptr.add(i), elem.clone()); |
2064 | 0 | local_len.increment_len(1); |
2065 | 0 | } |
2066 | | } |
2067 | 0 | v |
2068 | | } |
2069 | 0 | } |
2070 | | } |
2071 | | |
2072 | | impl<A: Array> ops::Deref for SmallVec<A> { |
2073 | | type Target = [A::Item]; |
2074 | | #[inline] |
2075 | 23.7M | fn deref(&self) -> &[A::Item] { |
2076 | | unsafe { |
2077 | 23.7M | let (ptr, len, _) = self.triple(); |
2078 | 23.7M | slice::from_raw_parts(ptr.as_ptr(), len) |
2079 | | } |
2080 | 23.7M | } <smallvec::SmallVec<[u8; 64]> as core::ops::deref::Deref>::deref Line | Count | Source | 2075 | 1.94M | fn deref(&self) -> &[A::Item] { | 2076 | | unsafe { | 2077 | 1.94M | let (ptr, len, _) = self.triple(); | 2078 | 1.94M | slice::from_raw_parts(ptr.as_ptr(), len) | 2079 | | } | 2080 | 1.94M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]> as core::ops::deref::Deref>::deref <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::ops::deref::Deref>::deref Line | Count | Source | 2075 | 1.67M | fn deref(&self) -> &[A::Item] { | 2076 | | unsafe { | 2077 | 1.67M | let (ptr, len, _) = self.triple(); | 2078 | 1.67M | slice::from_raw_parts(ptr.as_ptr(), len) | 2079 | | } | 2080 | 1.67M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]> as core::ops::deref::Deref>::deref <smallvec::SmallVec<[exr::meta::header::Header; 3]> as core::ops::deref::Deref>::deref Line | Count | Source | 2075 | 5.27M | fn deref(&self) -> &[A::Item] { | 2076 | | unsafe { | 2077 | 5.27M | let (ptr, len, _) = self.triple(); | 2078 | 5.27M | slice::from_raw_parts(ptr.as_ptr(), len) | 2079 | | } | 2080 | 5.27M | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::ops::deref::Deref>::deref Line | Count | Source | 2075 | 1.20M | fn deref(&self) -> &[A::Item] { | 2076 | | unsafe { | 2077 | 1.20M | let (ptr, len, _) = self.triple(); | 2078 | 1.20M | slice::from_raw_parts(ptr.as_ptr(), len) | 2079 | | } | 2080 | 1.20M | } |
<smallvec::SmallVec<[u8; 16]> as core::ops::deref::Deref>::deref Line | Count | Source | 2075 | 177k | fn deref(&self) -> &[A::Item] { | 2076 | | unsafe { | 2077 | 177k | let (ptr, len, _) = self.triple(); | 2078 | 177k | slice::from_raw_parts(ptr.as_ptr(), len) | 2079 | | } | 2080 | 177k | } |
<smallvec::SmallVec<[u8; 24]> as core::ops::deref::Deref>::deref Line | Count | Source | 2075 | 13.5M | fn deref(&self) -> &[A::Item] { | 2076 | | unsafe { | 2077 | 13.5M | let (ptr, len, _) = self.triple(); | 2078 | 13.5M | slice::from_raw_parts(ptr.as_ptr(), len) | 2079 | | } | 2080 | 13.5M | } |
Unexecuted instantiation: <smallvec::SmallVec<[u8; 8]> as core::ops::deref::Deref>::deref Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]> as core::ops::deref::Deref>::deref <smallvec::SmallVec<[u32; 2]> as core::ops::deref::Deref>::deref Line | Count | Source | 2075 | 12.1k | fn deref(&self) -> &[A::Item] { | 2076 | | unsafe { | 2077 | 12.1k | let (ptr, len, _) = self.triple(); | 2078 | 12.1k | slice::from_raw_parts(ptr.as_ptr(), len) | 2079 | | } | 2080 | 12.1k | } |
Unexecuted instantiation: <smallvec::SmallVec<_> as core::ops::deref::Deref>::deref |
2081 | | } |
2082 | | |
2083 | | impl<A: Array> ops::DerefMut for SmallVec<A> { |
2084 | | #[inline] |
2085 | 15.7M | fn deref_mut(&mut self) -> &mut [A::Item] { |
2086 | 15.7M | unsafe { |
2087 | 15.7M | let (ptr, &mut len, _) = self.triple_mut(); |
2088 | 15.7M | slice::from_raw_parts_mut(ptr.as_ptr(), len) |
2089 | 15.7M | } |
2090 | 15.7M | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::ops::deref::DerefMut>::deref_mut Line | Count | Source | 2085 | 868k | fn deref_mut(&mut self) -> &mut [A::Item] { | 2086 | 868k | unsafe { | 2087 | 868k | let (ptr, &mut len, _) = self.triple_mut(); | 2088 | 868k | slice::from_raw_parts_mut(ptr.as_ptr(), len) | 2089 | 868k | } | 2090 | 868k | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]> as core::ops::deref::DerefMut>::deref_mut Line | Count | Source | 2085 | 874k | fn deref_mut(&mut self) -> &mut [A::Item] { | 2086 | 874k | unsafe { | 2087 | 874k | let (ptr, &mut len, _) = self.triple_mut(); | 2088 | 874k | slice::from_raw_parts_mut(ptr.as_ptr(), len) | 2089 | 874k | } | 2090 | 874k | } |
<smallvec::SmallVec<[u8; 64]> as core::ops::deref::DerefMut>::deref_mut Line | Count | Source | 2085 | 3.50M | fn deref_mut(&mut self) -> &mut [A::Item] { | 2086 | 3.50M | unsafe { | 2087 | 3.50M | let (ptr, &mut len, _) = self.triple_mut(); | 2088 | 3.50M | slice::from_raw_parts_mut(ptr.as_ptr(), len) | 2089 | 3.50M | } | 2090 | 3.50M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]> as core::ops::deref::DerefMut>::deref_mut Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]> as core::ops::deref::DerefMut>::deref_mut <smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::ops::deref::DerefMut>::deref_mut Line | Count | Source | 2085 | 961k | fn deref_mut(&mut self) -> &mut [A::Item] { | 2086 | 961k | unsafe { | 2087 | 961k | let (ptr, &mut len, _) = self.triple_mut(); | 2088 | 961k | slice::from_raw_parts_mut(ptr.as_ptr(), len) | 2089 | 961k | } | 2090 | 961k | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]> as core::ops::deref::DerefMut>::deref_mut <smallvec::SmallVec<[u8; 16]> as core::ops::deref::DerefMut>::deref_mut Line | Count | Source | 2085 | 837k | fn deref_mut(&mut self) -> &mut [A::Item] { | 2086 | 837k | unsafe { | 2087 | 837k | let (ptr, &mut len, _) = self.triple_mut(); | 2088 | 837k | slice::from_raw_parts_mut(ptr.as_ptr(), len) | 2089 | 837k | } | 2090 | 837k | } |
<smallvec::SmallVec<[u8; 24]> as core::ops::deref::DerefMut>::deref_mut Line | Count | Source | 2085 | 8.67M | fn deref_mut(&mut self) -> &mut [A::Item] { | 2086 | 8.67M | unsafe { | 2087 | 8.67M | let (ptr, &mut len, _) = self.triple_mut(); | 2088 | 8.67M | slice::from_raw_parts_mut(ptr.as_ptr(), len) | 2089 | 8.67M | } | 2090 | 8.67M | } |
Unexecuted instantiation: <smallvec::SmallVec<[u8; 8]> as core::ops::deref::DerefMut>::deref_mut Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]> as core::ops::deref::DerefMut>::deref_mut <smallvec::SmallVec<[u32; 2]> as core::ops::deref::DerefMut>::deref_mut Line | Count | Source | 2085 | 47 | fn deref_mut(&mut self) -> &mut [A::Item] { | 2086 | 47 | unsafe { | 2087 | 47 | let (ptr, &mut len, _) = self.triple_mut(); | 2088 | 47 | slice::from_raw_parts_mut(ptr.as_ptr(), len) | 2089 | 47 | } | 2090 | 47 | } |
Unexecuted instantiation: <smallvec::SmallVec<_> as core::ops::deref::DerefMut>::deref_mut |
2091 | | } |
2092 | | |
2093 | | impl<A: Array> AsRef<[A::Item]> for SmallVec<A> { |
2094 | | #[inline] |
2095 | 0 | fn as_ref(&self) -> &[A::Item] { |
2096 | 0 | self |
2097 | 0 | } |
2098 | | } |
2099 | | |
2100 | | impl<A: Array> AsMut<[A::Item]> for SmallVec<A> { |
2101 | | #[inline] |
2102 | 1.72M | fn as_mut(&mut self) -> &mut [A::Item] { |
2103 | 1.72M | self |
2104 | 1.72M | } <smallvec::SmallVec<[u8; 64]> as core::convert::AsMut<[u8]>>::as_mut Line | Count | Source | 2102 | 1.72M | fn as_mut(&mut self) -> &mut [A::Item] { | 2103 | 1.72M | self | 2104 | 1.72M | } |
Unexecuted instantiation: <smallvec::SmallVec<_> as core::convert::AsMut<[<_ as smallvec::Array>::Item]>>::as_mut |
2105 | | } |
2106 | | |
2107 | | impl<A: Array> Borrow<[A::Item]> for SmallVec<A> { |
2108 | | #[inline] |
2109 | 0 | fn borrow(&self) -> &[A::Item] { |
2110 | 0 | self |
2111 | 0 | } |
2112 | | } |
2113 | | |
2114 | | impl<A: Array> BorrowMut<[A::Item]> for SmallVec<A> { |
2115 | | #[inline] |
2116 | 0 | fn borrow_mut(&mut self) -> &mut [A::Item] { |
2117 | 0 | self |
2118 | 0 | } |
2119 | | } |
2120 | | |
2121 | | #[cfg(feature = "write")] |
2122 | | #[cfg_attr(docsrs, doc(cfg(feature = "write")))] |
2123 | | impl<A: Array<Item = u8>> io::Write for SmallVec<A> { |
2124 | | #[inline] |
2125 | | fn write(&mut self, buf: &[u8]) -> io::Result<usize> { |
2126 | | self.extend_from_slice(buf); |
2127 | | Ok(buf.len()) |
2128 | | } |
2129 | | |
2130 | | #[inline] |
2131 | | fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { |
2132 | | self.extend_from_slice(buf); |
2133 | | Ok(()) |
2134 | | } |
2135 | | |
2136 | | #[inline] |
2137 | | fn flush(&mut self) -> io::Result<()> { |
2138 | | Ok(()) |
2139 | | } |
2140 | | } |
2141 | | |
2142 | | #[cfg(feature = "serde")] |
2143 | | #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] |
2144 | | impl<A: Array> Serialize for SmallVec<A> |
2145 | | where |
2146 | | A::Item: Serialize, |
2147 | | { |
2148 | | fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { |
2149 | | let mut state = serializer.serialize_seq(Some(self.len()))?; |
2150 | | for item in self { |
2151 | | state.serialize_element(&item)?; |
2152 | | } |
2153 | | state.end() |
2154 | | } |
2155 | | } |
2156 | | |
2157 | | #[cfg(feature = "serde")] |
2158 | | #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] |
2159 | | impl<'de, A: Array> Deserialize<'de> for SmallVec<A> |
2160 | | where |
2161 | | A::Item: Deserialize<'de>, |
2162 | | { |
2163 | | fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { |
2164 | | deserializer.deserialize_seq(SmallVecVisitor { |
2165 | | phantom: PhantomData, |
2166 | | }) |
2167 | | } |
2168 | | } |
2169 | | |
2170 | | #[cfg(feature = "serde")] |
2171 | | struct SmallVecVisitor<A> { |
2172 | | phantom: PhantomData<A>, |
2173 | | } |
2174 | | |
2175 | | #[cfg(feature = "serde")] |
2176 | | impl<'de, A: Array> Visitor<'de> for SmallVecVisitor<A> |
2177 | | where |
2178 | | A::Item: Deserialize<'de>, |
2179 | | { |
2180 | | type Value = SmallVec<A>; |
2181 | | |
2182 | | fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { |
2183 | | formatter.write_str("a sequence") |
2184 | | } |
2185 | | |
2186 | | fn visit_seq<B>(self, mut seq: B) -> Result<Self::Value, B::Error> |
2187 | | where |
2188 | | B: SeqAccess<'de>, |
2189 | | { |
2190 | | use serde::de::Error; |
2191 | | let len = seq.size_hint().unwrap_or(0); |
2192 | | let mut values = SmallVec::new(); |
2193 | | values.try_reserve(len).map_err(B::Error::custom)?; |
2194 | | |
2195 | | while let Some(value) = seq.next_element()? { |
2196 | | values.push(value); |
2197 | | } |
2198 | | |
2199 | | Ok(values) |
2200 | | } |
2201 | | } |
2202 | | |
2203 | | #[cfg(feature = "malloc_size_of")] |
2204 | | impl<A: Array> MallocShallowSizeOf for SmallVec<A> { |
2205 | | fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { |
2206 | | if self.spilled() { |
2207 | | unsafe { ops.malloc_size_of(self.as_ptr()) } |
2208 | | } else { |
2209 | | 0 |
2210 | | } |
2211 | | } |
2212 | | } |
2213 | | |
2214 | | #[cfg(feature = "malloc_size_of")] |
2215 | | impl<A> MallocSizeOf for SmallVec<A> |
2216 | | where |
2217 | | A: Array, |
2218 | | A::Item: MallocSizeOf, |
2219 | | { |
2220 | | fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { |
2221 | | let mut n = self.shallow_size_of(ops); |
2222 | | for elem in self.iter() { |
2223 | | n += elem.size_of(ops); |
2224 | | } |
2225 | | n |
2226 | | } |
2227 | | } |
2228 | | |
2229 | | #[cfg(feature = "specialization")] |
2230 | | trait SpecFrom<A: Array, S> { |
2231 | | fn spec_from(slice: S) -> SmallVec<A>; |
2232 | | } |
2233 | | |
2234 | | #[cfg(feature = "specialization")] |
2235 | | mod specialization; |
2236 | | |
2237 | | #[cfg(feature = "arbitrary")] |
2238 | | mod arbitrary; |
2239 | | |
2240 | | #[cfg(feature = "specialization")] |
2241 | | impl<'a, A: Array> SpecFrom<A, &'a [A::Item]> for SmallVec<A> |
2242 | | where |
2243 | | A::Item: Copy, |
2244 | | { |
2245 | | #[inline] |
2246 | | fn spec_from(slice: &'a [A::Item]) -> SmallVec<A> { |
2247 | | SmallVec::from_slice(slice) |
2248 | | } |
2249 | | } |
2250 | | |
2251 | | impl<'a, A: Array> From<&'a [A::Item]> for SmallVec<A> |
2252 | | where |
2253 | | A::Item: Clone, |
2254 | | { |
2255 | | #[cfg(not(feature = "specialization"))] |
2256 | | #[inline] |
2257 | 7.69M | fn from(slice: &'a [A::Item]) -> SmallVec<A> { |
2258 | 7.69M | slice.iter().cloned().collect() |
2259 | 7.69M | } <smallvec::SmallVec<[exr::meta::header::Header; 3]> as core::convert::From<&[exr::meta::header::Header]>>::from Line | Count | Source | 2257 | 868k | fn from(slice: &'a [A::Item]) -> SmallVec<A> { | 2258 | 868k | slice.iter().cloned().collect() | 2259 | 868k | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::convert::From<&[exr::meta::attribute::ChannelDescription]>>::from Line | Count | Source | 2257 | 884k | fn from(slice: &'a [A::Item]) -> SmallVec<A> { | 2258 | 884k | slice.iter().cloned().collect() | 2259 | 884k | } |
<smallvec::SmallVec<[u8; 16]> as core::convert::From<&[u8]>>::from Line | Count | Source | 2257 | 1.03M | fn from(slice: &'a [A::Item]) -> SmallVec<A> { | 2258 | 1.03M | slice.iter().cloned().collect() | 2259 | 1.03M | } |
<smallvec::SmallVec<[u8; 24]> as core::convert::From<&[u8]>>::from Line | Count | Source | 2257 | 4.90M | fn from(slice: &'a [A::Item]) -> SmallVec<A> { | 2258 | 4.90M | slice.iter().cloned().collect() | 2259 | 4.90M | } |
Unexecuted instantiation: <smallvec::SmallVec<[u32; 2]> as core::convert::From<&[u32]>>::from Unexecuted instantiation: <smallvec::SmallVec<_> as core::convert::From<&[<_ as smallvec::Array>::Item]>>::from |
2260 | | |
2261 | | #[cfg(feature = "specialization")] |
2262 | | #[inline] |
2263 | | fn from(slice: &'a [A::Item]) -> SmallVec<A> { |
2264 | | SmallVec::spec_from(slice) |
2265 | | } |
2266 | | } |
2267 | | |
2268 | | impl<A: Array> From<Vec<A::Item>> for SmallVec<A> { |
2269 | | #[inline] |
2270 | 0 | fn from(vec: Vec<A::Item>) -> SmallVec<A> { |
2271 | 0 | SmallVec::from_vec(vec) |
2272 | 0 | } |
2273 | | } |
2274 | | |
2275 | | impl<A: Array> From<A> for SmallVec<A> { |
2276 | | #[inline] |
2277 | 0 | fn from(array: A) -> SmallVec<A> { |
2278 | 0 | SmallVec::from_buf(array) |
2279 | 0 | } |
2280 | | } |
2281 | | |
2282 | | impl<A: Array, I: SliceIndex<[A::Item]>> ops::Index<I> for SmallVec<A> { |
2283 | | type Output = I::Output; |
2284 | | |
2285 | 4.65M | fn index(&self, index: I) -> &I::Output { |
2286 | 4.65M | &(**self)[index] |
2287 | 4.65M | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::ops::index::Index<usize>>::index Line | Count | Source | 2285 | 1.67M | fn index(&self, index: I) -> &I::Output { | 2286 | 1.67M | &(**self)[index] | 2287 | 1.67M | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]> as core::ops::index::Index<usize>>::index Line | Count | Source | 2285 | 889k | fn index(&self, index: I) -> &I::Output { | 2286 | 889k | &(**self)[index] | 2287 | 889k | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]> as core::ops::index::Index<usize>>::index Unexecuted instantiation: <smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::ops::index::Index<core::ops::range::RangeFull>>::index <smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::ops::index::Index<usize>>::index Line | Count | Source | 2285 | 12 | fn index(&self, index: I) -> &I::Output { | 2286 | 12 | &(**self)[index] | 2287 | 12 | } |
Unexecuted instantiation: <smallvec::SmallVec<[u8; 16]> as core::ops::index::Index<core::ops::range::RangeFull>>::index <smallvec::SmallVec<[u8; 24]> as core::ops::index::Index<core::ops::range::RangeFull>>::index Line | Count | Source | 2285 | 2.09M | fn index(&self, index: I) -> &I::Output { | 2286 | 2.09M | &(**self)[index] | 2287 | 2.09M | } |
Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]> as core::ops::index::Index<usize>>::index Unexecuted instantiation: <smallvec::SmallVec<_> as core::ops::index::Index<_>>::index |
2288 | | } |
2289 | | |
2290 | | impl<A: Array, I: SliceIndex<[A::Item]>> ops::IndexMut<I> for SmallVec<A> { |
2291 | 13.9M | fn index_mut(&mut self, index: I) -> &mut I::Output { |
2292 | 13.9M | &mut (&mut **self)[index] |
2293 | 13.9M | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut Line | Count | Source | 2291 | 2.61k | fn index_mut(&mut self, index: I) -> &mut I::Output { | 2292 | 2.61k | &mut (&mut **self)[index] | 2293 | 2.61k | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut Line | Count | Source | 2291 | 874k | fn index_mut(&mut self, index: I) -> &mut I::Output { | 2292 | 874k | &mut (&mut **self)[index] | 2293 | 874k | } |
<smallvec::SmallVec<[u8; 64]> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut Line | Count | Source | 2291 | 1.77M | fn index_mut(&mut self, index: I) -> &mut I::Output { | 2292 | 1.77M | &mut (&mut **self)[index] | 2293 | 1.77M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut <smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut Line | Count | Source | 2291 | 961k | fn index_mut(&mut self, index: I) -> &mut I::Output { | 2292 | 961k | &mut (&mut **self)[index] | 2293 | 961k | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut <smallvec::SmallVec<[u8; 16]> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut Line | Count | Source | 2291 | 837k | fn index_mut(&mut self, index: I) -> &mut I::Output { | 2292 | 837k | &mut (&mut **self)[index] | 2293 | 837k | } |
<smallvec::SmallVec<[u8; 24]> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut Line | Count | Source | 2291 | 8.67M | fn index_mut(&mut self, index: I) -> &mut I::Output { | 2292 | 8.67M | &mut (&mut **self)[index] | 2293 | 8.67M | } |
Unexecuted instantiation: <smallvec::SmallVec<[u8; 8]> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut <smallvec::SmallVec<[u32; 2]> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut Line | Count | Source | 2291 | 47 | fn index_mut(&mut self, index: I) -> &mut I::Output { | 2292 | 47 | &mut (&mut **self)[index] | 2293 | 47 | } |
Unexecuted instantiation: <smallvec::SmallVec<_> as core::ops::index::IndexMut<_>>::index_mut Unexecuted instantiation: <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::ops::index::IndexMut<usize>>::index_mut <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::ops::index::IndexMut<usize>>::index_mut Line | Count | Source | 2291 | 866k | fn index_mut(&mut self, index: I) -> &mut I::Output { | 2292 | 866k | &mut (&mut **self)[index] | 2293 | 866k | } |
|
2294 | | } |
2295 | | |
2296 | | #[allow(deprecated)] |
2297 | | impl<A: Array> ExtendFromSlice<A::Item> for SmallVec<A> |
2298 | | where |
2299 | | A::Item: Copy, |
2300 | | { |
2301 | 0 | fn extend_from_slice(&mut self, other: &[A::Item]) { |
2302 | 0 | SmallVec::extend_from_slice(self, other) |
2303 | 0 | } |
2304 | | } |
2305 | | |
2306 | | impl<A: Array> FromIterator<A::Item> for SmallVec<A> { |
2307 | | #[inline] |
2308 | 7.76M | fn from_iter<I: IntoIterator<Item = A::Item>>(iterable: I) -> SmallVec<A> { |
2309 | 7.76M | let mut v = SmallVec::new(); |
2310 | 7.76M | v.extend(iterable); |
2311 | 7.76M | v |
2312 | 7.76M | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::iter::traits::collect::FromIterator<alloc::vec::Vec<u64>>>::from_iter::<core::iter::adapters::GenericShunt<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::header::Header>, <exr::meta::MetaData>::read_offset_tables<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>>::{closure#0}>, core::result::Result<core::convert::Infallible, exr::error::Error>>>Line | Count | Source | 2308 | 2.85k | fn from_iter<I: IntoIterator<Item = A::Item>>(iterable: I) -> SmallVec<A> { | 2309 | 2.85k | let mut v = SmallVec::new(); | 2310 | 2.85k | v.extend(iterable); | 2311 | 2.85k | v | 2312 | 2.85k | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]> as core::iter::traits::collect::FromIterator<exr::meta::header::Header>>::from_iter::<core::iter::adapters::cloned::Cloned<core::slice::iter::Iter<exr::meta::header::Header>>> Line | Count | Source | 2308 | 868k | fn from_iter<I: IntoIterator<Item = A::Item>>(iterable: I) -> SmallVec<A> { | 2309 | 868k | let mut v = SmallVec::new(); | 2310 | 868k | v.extend(iterable); | 2311 | 868k | v | 2312 | 868k | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::iter::traits::collect::FromIterator<exr::meta::attribute::ChannelDescription>>::from_iter::<core::iter::adapters::cloned::Cloned<core::slice::iter::Iter<exr::meta::attribute::ChannelDescription>>> Line | Count | Source | 2308 | 884k | fn from_iter<I: IntoIterator<Item = A::Item>>(iterable: I) -> SmallVec<A> { | 2309 | 884k | let mut v = SmallVec::new(); | 2310 | 884k | v.extend(iterable); | 2311 | 884k | v | 2312 | 884k | } |
<smallvec::SmallVec<[u8; 16]> as core::iter::traits::collect::FromIterator<u8>>::from_iter::<core::iter::adapters::cloned::Cloned<core::slice::iter::Iter<u8>>> Line | Count | Source | 2308 | 1.03M | fn from_iter<I: IntoIterator<Item = A::Item>>(iterable: I) -> SmallVec<A> { | 2309 | 1.03M | let mut v = SmallVec::new(); | 2310 | 1.03M | v.extend(iterable); | 2311 | 1.03M | v | 2312 | 1.03M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]> as core::iter::traits::collect::FromIterator<exr::image::AnyChannel<exr::image::FlatSamples>>>::from_iter::<core::iter::adapters::map::Map<smallvec::IntoIter<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>, <exr::image::Layer<exr::image::crop::CroppedChannels<exr::image::AnyChannels<exr::image::FlatSamples>>> as exr::image::crop::ApplyCroppedView>::reallocate_cropped::{closure#0}>>Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]> as core::iter::traits::collect::FromIterator<exr::compression::piz::ChannelData>>::from_iter::<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::attribute::ChannelDescription>, exr::compression::piz::decompress::{closure#0}>>Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]> as core::iter::traits::collect::FromIterator<exr::compression::piz::ChannelData>>::from_iter::<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::attribute::ChannelDescription>, exr::compression::piz::compress::{closure#0}>>Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]> as core::iter::traits::collect::FromIterator<exr::block::samples::Sample>>::from_iter::<exr::image::FlatSampleIterator> <smallvec::SmallVec<[u8; 24]> as core::iter::traits::collect::FromIterator<u8>>::from_iter::<core::iter::adapters::GenericShunt<core::iter::adapters::map::Map<core::str::iter::Chars, <exr::meta::attribute::Text>::new_or_none<&str>::{closure#0}>, core::option::Option<core::convert::Infallible>>>Line | Count | Source | 2308 | 41.6k | fn from_iter<I: IntoIterator<Item = A::Item>>(iterable: I) -> SmallVec<A> { | 2309 | 41.6k | let mut v = SmallVec::new(); | 2310 | 41.6k | v.extend(iterable); | 2311 | 41.6k | v | 2312 | 41.6k | } |
<smallvec::SmallVec<[u8; 24]> as core::iter::traits::collect::FromIterator<u8>>::from_iter::<core::iter::adapters::cloned::Cloned<core::slice::iter::Iter<u8>>> Line | Count | Source | 2308 | 4.90M | fn from_iter<I: IntoIterator<Item = A::Item>>(iterable: I) -> SmallVec<A> { | 2309 | 4.90M | let mut v = SmallVec::new(); | 2310 | 4.90M | v.extend(iterable); | 2311 | 4.90M | v | 2312 | 4.90M | } |
<smallvec::SmallVec<[u8; 8]> as core::iter::traits::collect::FromIterator<u8>>::from_iter::<core::iter::adapters::map::Map<core::ops::range::Range<usize>, <exr::meta::attribute::TimeCode>::unpack_user_data_from_u32::{closure#0}>>Line | Count | Source | 2308 | 26.4k | fn from_iter<I: IntoIterator<Item = A::Item>>(iterable: I) -> SmallVec<A> { | 2309 | 26.4k | let mut v = SmallVec::new(); | 2310 | 26.4k | v.extend(iterable); | 2311 | 26.4k | v | 2312 | 26.4k | } |
Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]> as core::iter::traits::collect::FromIterator<usize>>::from_iter::<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::attribute::ChannelDescription>, <exr::block::lines::LineIndex>::lines_in_block::{closure#0}>>Unexecuted instantiation: <smallvec::SmallVec<[u32; 2]> as core::iter::traits::collect::FromIterator<u32>>::from_iter::<core::iter::adapters::cloned::Cloned<core::slice::iter::Iter<u32>>> Unexecuted instantiation: <smallvec::SmallVec<_> as core::iter::traits::collect::FromIterator<<_ as smallvec::Array>::Item>>::from_iter::<_> Unexecuted instantiation: <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::iter::traits::collect::FromIterator<alloc::vec::Vec<u64>>>::from_iter::<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::header::Header>, <exr::block::writer::ChunkWriter<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::new_for_buffered::{closure#1}>><smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::iter::traits::collect::FromIterator<alloc::vec::Vec<u64>>>::from_iter::<core::iter::adapters::GenericShunt<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::header::Header>, <exr::meta::MetaData>::read_offset_tables<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::{closure#0}>, core::result::Result<core::convert::Infallible, exr::error::Error>>>Line | Count | Source | 2308 | 95 | fn from_iter<I: IntoIterator<Item = A::Item>>(iterable: I) -> SmallVec<A> { | 2309 | 95 | let mut v = SmallVec::new(); | 2310 | 95 | v.extend(iterable); | 2311 | 95 | v | 2312 | 95 | } |
<smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::iter::traits::collect::FromIterator<alloc::vec::Vec<u64>>>::from_iter::<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::header::Header>, <exr::block::writer::ChunkWriter<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>>>::new_for_buffered::{closure#1}>>Line | Count | Source | 2308 | 95 | fn from_iter<I: IntoIterator<Item = A::Item>>(iterable: I) -> SmallVec<A> { | 2309 | 95 | let mut v = SmallVec::new(); | 2310 | 95 | v.extend(iterable); | 2311 | 95 | v | 2312 | 95 | } |
|
2313 | | } |
2314 | | |
2315 | | impl<A: Array> Extend<A::Item> for SmallVec<A> { |
2316 | 9.49M | fn extend<I: IntoIterator<Item = A::Item>>(&mut self, iterable: I) { |
2317 | 9.49M | let mut iter = iterable.into_iter(); |
2318 | 9.49M | let (lower_size_bound, _) = iter.size_hint(); |
2319 | 9.49M | self.reserve(lower_size_bound); |
2320 | | |
2321 | | unsafe { |
2322 | 9.49M | let (ptr, len_ptr, cap) = self.triple_mut(); |
2323 | 9.49M | let ptr = ptr.as_ptr(); |
2324 | 9.49M | let mut len = SetLenOnDrop::new(len_ptr); |
2325 | 81.0M | while len.get() < cap { |
2326 | 80.8M | if let Some(out) = iter.next() { |
2327 | 71.5M | ptr::write(ptr.add(len.get()), out); |
2328 | 71.5M | len.increment_len(1); |
2329 | 71.5M | } else { |
2330 | 9.27M | return; |
2331 | | } |
2332 | | } |
2333 | | } |
2334 | | |
2335 | 227k | for elem in iter { |
2336 | 12.8k | self.push(elem); |
2337 | 12.8k | } |
2338 | 9.49M | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::iter::traits::collect::Extend<alloc::vec::Vec<u64>>>::extend::<core::iter::adapters::GenericShunt<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::header::Header>, <exr::meta::MetaData>::read_offset_tables<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>>::{closure#0}>, core::result::Result<core::convert::Infallible, exr::error::Error>>>Line | Count | Source | 2316 | 2.85k | fn extend<I: IntoIterator<Item = A::Item>>(&mut self, iterable: I) { | 2317 | 2.85k | let mut iter = iterable.into_iter(); | 2318 | 2.85k | let (lower_size_bound, _) = iter.size_hint(); | 2319 | 2.85k | self.reserve(lower_size_bound); | 2320 | | | 2321 | | unsafe { | 2322 | 2.85k | let (ptr, len_ptr, cap) = self.triple_mut(); | 2323 | 2.85k | let ptr = ptr.as_ptr(); | 2324 | 2.85k | let mut len = SetLenOnDrop::new(len_ptr); | 2325 | 6.55k | while len.get() < cap { | 2326 | 6.07k | if let Some(out) = iter.next() { | 2327 | 3.70k | ptr::write(ptr.add(len.get()), out); | 2328 | 3.70k | len.increment_len(1); | 2329 | 3.70k | } else { | 2330 | 2.37k | return; | 2331 | | } | 2332 | | } | 2333 | | } | 2334 | | | 2335 | 13.3k | for elem in iter { | 2336 | 12.8k | self.push(elem); | 2337 | 12.8k | } | 2338 | 2.85k | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]> as core::iter::traits::collect::Extend<exr::meta::header::Header>>::extend::<core::iter::adapters::cloned::Cloned<core::slice::iter::Iter<exr::meta::header::Header>>> Line | Count | Source | 2316 | 868k | fn extend<I: IntoIterator<Item = A::Item>>(&mut self, iterable: I) { | 2317 | 868k | let mut iter = iterable.into_iter(); | 2318 | 868k | let (lower_size_bound, _) = iter.size_hint(); | 2319 | 868k | self.reserve(lower_size_bound); | 2320 | | | 2321 | | unsafe { | 2322 | 868k | let (ptr, len_ptr, cap) = self.triple_mut(); | 2323 | 868k | let ptr = ptr.as_ptr(); | 2324 | 868k | let mut len = SetLenOnDrop::new(len_ptr); | 2325 | 1.74M | while len.get() < cap { | 2326 | 1.74M | if let Some(out) = iter.next() { | 2327 | 880k | ptr::write(ptr.add(len.get()), out); | 2328 | 880k | len.increment_len(1); | 2329 | 880k | } else { | 2330 | 868k | return; | 2331 | | } | 2332 | | } | 2333 | | } | 2334 | | | 2335 | 127 | for elem in iter { | 2336 | 0 | self.push(elem); | 2337 | 0 | } | 2338 | 868k | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::iter::traits::collect::Extend<exr::meta::attribute::ChannelDescription>>::extend::<core::iter::adapters::cloned::Cloned<core::slice::iter::Iter<exr::meta::attribute::ChannelDescription>>> Line | Count | Source | 2316 | 884k | fn extend<I: IntoIterator<Item = A::Item>>(&mut self, iterable: I) { | 2317 | 884k | let mut iter = iterable.into_iter(); | 2318 | 884k | let (lower_size_bound, _) = iter.size_hint(); | 2319 | 884k | self.reserve(lower_size_bound); | 2320 | | | 2321 | | unsafe { | 2322 | 884k | let (ptr, len_ptr, cap) = self.triple_mut(); | 2323 | 884k | let ptr = ptr.as_ptr(); | 2324 | 884k | let mut len = SetLenOnDrop::new(len_ptr); | 2325 | 4.39M | while len.get() < cap { | 2326 | 4.39M | if let Some(out) = iter.next() { | 2327 | 3.51M | ptr::write(ptr.add(len.get()), out); | 2328 | 3.51M | len.increment_len(1); | 2329 | 3.51M | } else { | 2330 | 884k | return; | 2331 | | } | 2332 | | } | 2333 | | } | 2334 | | | 2335 | 0 | for elem in iter { | 2336 | 0 | self.push(elem); | 2337 | 0 | } | 2338 | 884k | } |
<smallvec::SmallVec<[u8; 16]> as core::iter::traits::collect::Extend<u8>>::extend::<core::iter::adapters::cloned::Cloned<core::slice::iter::Iter<u8>>> Line | Count | Source | 2316 | 1.03M | fn extend<I: IntoIterator<Item = A::Item>>(&mut self, iterable: I) { | 2317 | 1.03M | let mut iter = iterable.into_iter(); | 2318 | 1.03M | let (lower_size_bound, _) = iter.size_hint(); | 2319 | 1.03M | self.reserve(lower_size_bound); | 2320 | | | 2321 | | unsafe { | 2322 | 1.03M | let (ptr, len_ptr, cap) = self.triple_mut(); | 2323 | 1.03M | let ptr = ptr.as_ptr(); | 2324 | 1.03M | let mut len = SetLenOnDrop::new(len_ptr); | 2325 | 15.0M | while len.get() < cap { | 2326 | 14.9M | if let Some(out) = iter.next() { | 2327 | 13.9M | ptr::write(ptr.add(len.get()), out); | 2328 | 13.9M | len.increment_len(1); | 2329 | 13.9M | } else { | 2330 | 958k | return; | 2331 | | } | 2332 | | } | 2333 | | } | 2334 | | | 2335 | 81.2k | for elem in iter { | 2336 | 0 | self.push(elem); | 2337 | 0 | } | 2338 | 1.03M | } |
<smallvec::SmallVec<[u8; 64]> as core::iter::traits::collect::Extend<u8>>::extend::<core::iter::adapters::take::Take<core::iter::sources::repeat::Repeat<u8>>> Line | Count | Source | 2316 | 1.72M | fn extend<I: IntoIterator<Item = A::Item>>(&mut self, iterable: I) { | 2317 | 1.72M | let mut iter = iterable.into_iter(); | 2318 | 1.72M | let (lower_size_bound, _) = iter.size_hint(); | 2319 | 1.72M | self.reserve(lower_size_bound); | 2320 | | | 2321 | | unsafe { | 2322 | 1.72M | let (ptr, len_ptr, cap) = self.triple_mut(); | 2323 | 1.72M | let ptr = ptr.as_ptr(); | 2324 | 1.72M | let mut len = SetLenOnDrop::new(len_ptr); | 2325 | 37.3M | while len.get() < cap { | 2326 | 37.2M | if let Some(out) = iter.next() { | 2327 | 35.5M | ptr::write(ptr.add(len.get()), out); | 2328 | 35.5M | len.increment_len(1); | 2329 | 35.5M | } else { | 2330 | 1.62M | return; | 2331 | | } | 2332 | | } | 2333 | | } | 2334 | | | 2335 | 98.9k | for elem in iter { | 2336 | 0 | self.push(elem); | 2337 | 0 | } | 2338 | 1.72M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]> as core::iter::traits::collect::Extend<exr::image::AnyChannel<exr::image::FlatSamples>>>::extend::<core::iter::adapters::map::Map<smallvec::IntoIter<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]>, <exr::image::Layer<exr::image::crop::CroppedChannels<exr::image::AnyChannels<exr::image::FlatSamples>>> as exr::image::crop::ApplyCroppedView>::reallocate_cropped::{closure#0}>>Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]> as core::iter::traits::collect::Extend<exr::compression::piz::ChannelData>>::extend::<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::attribute::ChannelDescription>, exr::compression::piz::decompress::{closure#0}>>Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]> as core::iter::traits::collect::Extend<exr::compression::piz::ChannelData>>::extend::<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::attribute::ChannelDescription>, exr::compression::piz::compress::{closure#0}>>Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]> as core::iter::traits::collect::Extend<exr::block::samples::Sample>>::extend::<exr::image::FlatSampleIterator> <smallvec::SmallVec<[u8; 24]> as core::iter::traits::collect::Extend<u8>>::extend::<core::iter::adapters::GenericShunt<core::iter::adapters::map::Map<core::str::iter::Chars, <exr::meta::attribute::Text>::new_or_none<&str>::{closure#0}>, core::option::Option<core::convert::Infallible>>>Line | Count | Source | 2316 | 41.6k | fn extend<I: IntoIterator<Item = A::Item>>(&mut self, iterable: I) { | 2317 | 41.6k | let mut iter = iterable.into_iter(); | 2318 | 41.6k | let (lower_size_bound, _) = iter.size_hint(); | 2319 | 41.6k | self.reserve(lower_size_bound); | 2320 | | | 2321 | | unsafe { | 2322 | 41.6k | let (ptr, len_ptr, cap) = self.triple_mut(); | 2323 | 41.6k | let ptr = ptr.as_ptr(); | 2324 | 41.6k | let mut len = SetLenOnDrop::new(len_ptr); | 2325 | 83.3k | while len.get() < cap { | 2326 | 83.3k | if let Some(out) = iter.next() { | 2327 | 41.6k | ptr::write(ptr.add(len.get()), out); | 2328 | 41.6k | len.increment_len(1); | 2329 | 41.6k | } else { | 2330 | 41.6k | return; | 2331 | | } | 2332 | | } | 2333 | | } | 2334 | | | 2335 | 0 | for elem in iter { | 2336 | 0 | self.push(elem); | 2337 | 0 | } | 2338 | 41.6k | } |
<smallvec::SmallVec<[u8; 24]> as core::iter::traits::collect::Extend<u8>>::extend::<core::iter::adapters::cloned::Cloned<core::slice::iter::Iter<u8>>> Line | Count | Source | 2316 | 4.90M | fn extend<I: IntoIterator<Item = A::Item>>(&mut self, iterable: I) { | 2317 | 4.90M | let mut iter = iterable.into_iter(); | 2318 | 4.90M | let (lower_size_bound, _) = iter.size_hint(); | 2319 | 4.90M | self.reserve(lower_size_bound); | 2320 | | | 2321 | | unsafe { | 2322 | 4.90M | let (ptr, len_ptr, cap) = self.triple_mut(); | 2323 | 4.90M | let ptr = ptr.as_ptr(); | 2324 | 4.90M | let mut len = SetLenOnDrop::new(len_ptr); | 2325 | 22.2M | while len.get() < cap { | 2326 | 22.2M | if let Some(out) = iter.next() { | 2327 | 17.3M | ptr::write(ptr.add(len.get()), out); | 2328 | 17.3M | len.increment_len(1); | 2329 | 17.3M | } else { | 2330 | 4.89M | return; | 2331 | | } | 2332 | | } | 2333 | | } | 2334 | | | 2335 | 7.15k | for elem in iter { | 2336 | 0 | self.push(elem); | 2337 | 0 | } | 2338 | 4.90M | } |
<smallvec::SmallVec<[u8; 8]> as core::iter::traits::collect::Extend<u8>>::extend::<core::iter::adapters::map::Map<core::ops::range::Range<usize>, <exr::meta::attribute::TimeCode>::unpack_user_data_from_u32::{closure#0}>>Line | Count | Source | 2316 | 26.4k | fn extend<I: IntoIterator<Item = A::Item>>(&mut self, iterable: I) { | 2317 | 26.4k | let mut iter = iterable.into_iter(); | 2318 | 26.4k | let (lower_size_bound, _) = iter.size_hint(); | 2319 | 26.4k | self.reserve(lower_size_bound); | 2320 | | | 2321 | | unsafe { | 2322 | 26.4k | let (ptr, len_ptr, cap) = self.triple_mut(); | 2323 | 26.4k | let ptr = ptr.as_ptr(); | 2324 | 26.4k | let mut len = SetLenOnDrop::new(len_ptr); | 2325 | 237k | while len.get() < cap { | 2326 | 211k | if let Some(out) = iter.next() { | 2327 | 211k | ptr::write(ptr.add(len.get()), out); | 2328 | 211k | len.increment_len(1); | 2329 | 211k | } else { | 2330 | 0 | return; | 2331 | | } | 2332 | | } | 2333 | | } | 2334 | | | 2335 | 26.4k | for elem in iter { | 2336 | 0 | self.push(elem); | 2337 | 0 | } | 2338 | 26.4k | } |
Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]> as core::iter::traits::collect::Extend<usize>>::extend::<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::attribute::ChannelDescription>, <exr::block::lines::LineIndex>::lines_in_block::{closure#0}>>Unexecuted instantiation: <smallvec::SmallVec<[u32; 2]> as core::iter::traits::collect::Extend<u32>>::extend::<core::iter::adapters::cloned::Cloned<core::slice::iter::Iter<u32>>> Unexecuted instantiation: <smallvec::SmallVec<_> as core::iter::traits::collect::Extend<<_ as smallvec::Array>::Item>>::extend::<_> Unexecuted instantiation: <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::iter::traits::collect::Extend<alloc::vec::Vec<u64>>>::extend::<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::header::Header>, <exr::block::writer::ChunkWriter<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::new_for_buffered::{closure#1}>><smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::iter::traits::collect::Extend<alloc::vec::Vec<u64>>>::extend::<core::iter::adapters::GenericShunt<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::header::Header>, <exr::meta::MetaData>::read_offset_tables<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>::{closure#0}>, core::result::Result<core::convert::Infallible, exr::error::Error>>>Line | Count | Source | 2316 | 95 | fn extend<I: IntoIterator<Item = A::Item>>(&mut self, iterable: I) { | 2317 | 95 | let mut iter = iterable.into_iter(); | 2318 | 95 | let (lower_size_bound, _) = iter.size_hint(); | 2319 | 95 | self.reserve(lower_size_bound); | 2320 | | | 2321 | | unsafe { | 2322 | 95 | let (ptr, len_ptr, cap) = self.triple_mut(); | 2323 | 95 | let ptr = ptr.as_ptr(); | 2324 | 95 | let mut len = SetLenOnDrop::new(len_ptr); | 2325 | 190 | while len.get() < cap { | 2326 | 190 | if let Some(out) = iter.next() { | 2327 | 95 | ptr::write(ptr.add(len.get()), out); | 2328 | 95 | len.increment_len(1); | 2329 | 95 | } else { | 2330 | 95 | return; | 2331 | | } | 2332 | | } | 2333 | | } | 2334 | | | 2335 | 0 | for elem in iter { | 2336 | 0 | self.push(elem); | 2337 | 0 | } | 2338 | 95 | } |
<smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::iter::traits::collect::Extend<alloc::vec::Vec<u64>>>::extend::<core::iter::adapters::map::Map<core::slice::iter::Iter<exr::meta::header::Header>, <exr::block::writer::ChunkWriter<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>>>::new_for_buffered::{closure#1}>>Line | Count | Source | 2316 | 95 | fn extend<I: IntoIterator<Item = A::Item>>(&mut self, iterable: I) { | 2317 | 95 | let mut iter = iterable.into_iter(); | 2318 | 95 | let (lower_size_bound, _) = iter.size_hint(); | 2319 | 95 | self.reserve(lower_size_bound); | 2320 | | | 2321 | | unsafe { | 2322 | 95 | let (ptr, len_ptr, cap) = self.triple_mut(); | 2323 | 95 | let ptr = ptr.as_ptr(); | 2324 | 95 | let mut len = SetLenOnDrop::new(len_ptr); | 2325 | 190 | while len.get() < cap { | 2326 | 190 | if let Some(out) = iter.next() { | 2327 | 95 | ptr::write(ptr.add(len.get()), out); | 2328 | 95 | len.increment_len(1); | 2329 | 95 | } else { | 2330 | 95 | return; | 2331 | | } | 2332 | | } | 2333 | | } | 2334 | | | 2335 | 0 | for elem in iter { | 2336 | 0 | self.push(elem); | 2337 | 0 | } | 2338 | 95 | } |
|
2339 | | } |
2340 | | |
2341 | | impl<A: Array> fmt::Debug for SmallVec<A> |
2342 | | where |
2343 | | A::Item: fmt::Debug, |
2344 | | { |
2345 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2346 | 0 | f.debug_list().entries(self.iter()).finish() |
2347 | 0 | } Unexecuted instantiation: <smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::fmt::Debug>::fmt Unexecuted instantiation: <smallvec::SmallVec<[u8; 16]> as core::fmt::Debug>::fmt Unexecuted instantiation: <smallvec::SmallVec<[u8; 8]> as core::fmt::Debug>::fmt Unexecuted instantiation: <smallvec::SmallVec<_> as core::fmt::Debug>::fmt |
2348 | | } |
2349 | | |
2350 | | impl<A: Array> Default for SmallVec<A> { |
2351 | | #[inline] |
2352 | 0 | fn default() -> SmallVec<A> { |
2353 | 0 | SmallVec::new() |
2354 | 0 | } |
2355 | | } |
2356 | | |
2357 | | #[cfg(feature = "may_dangle")] |
2358 | | unsafe impl<#[may_dangle] A: Array> Drop for SmallVec<A> { |
2359 | | fn drop(&mut self) { |
2360 | | unsafe { |
2361 | | if self.spilled() { |
2362 | | let (ptr, &mut len) = self.data.heap_mut(); |
2363 | | Vec::from_raw_parts(ptr.as_ptr(), len, self.capacity); |
2364 | | } else { |
2365 | | ptr::drop_in_place(&mut self[..]); |
2366 | | } |
2367 | | } |
2368 | | } |
2369 | | } |
2370 | | |
2371 | | #[cfg(not(feature = "may_dangle"))] |
2372 | | impl<A: Array> Drop for SmallVec<A> { |
2373 | 13.7M | fn drop(&mut self) { |
2374 | | unsafe { |
2375 | 13.7M | if self.spilled() { |
2376 | 643k | let (ptr, &mut len) = self.data.heap_mut(); |
2377 | 643k | drop(Vec::from_raw_parts(ptr.as_ptr(), len, self.capacity)); |
2378 | 13.1M | } else { |
2379 | 13.1M | ptr::drop_in_place(&mut self[..]); |
2380 | 13.1M | } |
2381 | | } |
2382 | 13.7M | } <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::ops::drop::Drop>::drop Line | Count | Source | 2373 | 3.04k | fn drop(&mut self) { | 2374 | | unsafe { | 2375 | 3.04k | if self.spilled() { | 2376 | 429 | let (ptr, &mut len) = self.data.heap_mut(); | 2377 | 429 | drop(Vec::from_raw_parts(ptr.as_ptr(), len, self.capacity)); | 2378 | 2.61k | } else { | 2379 | 2.61k | ptr::drop_in_place(&mut self[..]); | 2380 | 2.61k | } | 2381 | | } | 2382 | 3.04k | } |
<smallvec::SmallVec<[exr::meta::header::Header; 3]> as core::ops::drop::Drop>::drop Line | Count | Source | 2373 | 875k | fn drop(&mut self) { | 2374 | | unsafe { | 2375 | 875k | if self.spilled() { | 2376 | 1.16k | let (ptr, &mut len) = self.data.heap_mut(); | 2377 | 1.16k | drop(Vec::from_raw_parts(ptr.as_ptr(), len, self.capacity)); | 2378 | 874k | } else { | 2379 | 874k | ptr::drop_in_place(&mut self[..]); | 2380 | 874k | } | 2381 | | } | 2382 | 875k | } |
<smallvec::SmallVec<[u8; 64]> as core::ops::drop::Drop>::drop Line | Count | Source | 2373 | 1.82M | fn drop(&mut self) { | 2374 | | unsafe { | 2375 | 1.82M | if self.spilled() { | 2376 | 53.6k | let (ptr, &mut len) = self.data.heap_mut(); | 2377 | 53.6k | drop(Vec::from_raw_parts(ptr.as_ptr(), len, self.capacity)); | 2378 | 1.77M | } else { | 2379 | 1.77M | ptr::drop_in_place(&mut self[..]); | 2380 | 1.77M | } | 2381 | | } | 2382 | 1.82M | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]> as core::ops::drop::Drop>::drop Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]> as core::ops::drop::Drop>::drop <smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::ops::drop::Drop>::drop Line | Count | Source | 2373 | 965k | fn drop(&mut self) { | 2374 | | unsafe { | 2375 | 965k | if self.spilled() { | 2376 | 3.51k | let (ptr, &mut len) = self.data.heap_mut(); | 2377 | 3.51k | drop(Vec::from_raw_parts(ptr.as_ptr(), len, self.capacity)); | 2378 | 961k | } else { | 2379 | 961k | ptr::drop_in_place(&mut self[..]); | 2380 | 961k | } | 2381 | | } | 2382 | 965k | } |
Unexecuted instantiation: <smallvec::SmallVec<[exr::block::samples::Sample; 8]> as core::ops::drop::Drop>::drop <smallvec::SmallVec<[u8; 16]> as core::ops::drop::Drop>::drop Line | Count | Source | 2373 | 1.03M | fn drop(&mut self) { | 2374 | | unsafe { | 2375 | 1.03M | if self.spilled() { | 2376 | 201k | let (ptr, &mut len) = self.data.heap_mut(); | 2377 | 201k | drop(Vec::from_raw_parts(ptr.as_ptr(), len, self.capacity)); | 2378 | 837k | } else { | 2379 | 837k | ptr::drop_in_place(&mut self[..]); | 2380 | 837k | } | 2381 | | } | 2382 | 1.03M | } |
<smallvec::SmallVec<[u8; 24]> as core::ops::drop::Drop>::drop Line | Count | Source | 2373 | 9.05M | fn drop(&mut self) { | 2374 | | unsafe { | 2375 | 9.05M | if self.spilled() { | 2376 | 382k | let (ptr, &mut len) = self.data.heap_mut(); | 2377 | 382k | drop(Vec::from_raw_parts(ptr.as_ptr(), len, self.capacity)); | 2378 | 8.67M | } else { | 2379 | 8.67M | ptr::drop_in_place(&mut self[..]); | 2380 | 8.67M | } | 2381 | | } | 2382 | 9.05M | } |
Unexecuted instantiation: <smallvec::SmallVec<[u8; 8]> as core::ops::drop::Drop>::drop Unexecuted instantiation: <smallvec::SmallVec<[usize; 8]> as core::ops::drop::Drop>::drop <smallvec::SmallVec<[u32; 2]> as core::ops::drop::Drop>::drop Line | Count | Source | 2373 | 72 | fn drop(&mut self) { | 2374 | | unsafe { | 2375 | 72 | if self.spilled() { | 2376 | 25 | let (ptr, &mut len) = self.data.heap_mut(); | 2377 | 25 | drop(Vec::from_raw_parts(ptr.as_ptr(), len, self.capacity)); | 2378 | 47 | } else { | 2379 | 47 | ptr::drop_in_place(&mut self[..]); | 2380 | 47 | } | 2381 | | } | 2382 | 72 | } |
Unexecuted instantiation: <smallvec::SmallVec<_> as core::ops::drop::Drop>::drop |
2383 | | } |
2384 | | |
2385 | | impl<A: Array> Clone for SmallVec<A> |
2386 | | where |
2387 | | A::Item: Clone, |
2388 | | { |
2389 | | #[inline] |
2390 | 6.83M | fn clone(&self) -> SmallVec<A> { |
2391 | 6.83M | SmallVec::from(self.as_slice()) |
2392 | 6.83M | } <smallvec::SmallVec<[exr::meta::header::Header; 3]> as core::clone::Clone>::clone Line | Count | Source | 2390 | 868k | fn clone(&self) -> SmallVec<A> { | 2391 | 868k | SmallVec::from(self.as_slice()) | 2392 | 868k | } |
<smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::clone::Clone>::clone Line | Count | Source | 2390 | 884k | fn clone(&self) -> SmallVec<A> { | 2391 | 884k | SmallVec::from(self.as_slice()) | 2392 | 884k | } |
<smallvec::SmallVec<[u8; 16]> as core::clone::Clone>::clone Line | Count | Source | 2390 | 177k | fn clone(&self) -> SmallVec<A> { | 2391 | 177k | SmallVec::from(self.as_slice()) | 2392 | 177k | } |
<smallvec::SmallVec<[u8; 24]> as core::clone::Clone>::clone Line | Count | Source | 2390 | 4.90M | fn clone(&self) -> SmallVec<A> { | 2391 | 4.90M | SmallVec::from(self.as_slice()) | 2392 | 4.90M | } |
Unexecuted instantiation: <smallvec::SmallVec<[u32; 2]> as core::clone::Clone>::clone Unexecuted instantiation: <smallvec::SmallVec<_> as core::clone::Clone>::clone |
2393 | | |
2394 | 0 | fn clone_from(&mut self, source: &Self) { |
2395 | | // Inspired from `impl Clone for Vec`. |
2396 | | |
2397 | | // drop anything that will not be overwritten |
2398 | 0 | self.truncate(source.len()); |
2399 | | |
2400 | | // self.len <= other.len due to the truncate above, so the |
2401 | | // slices here are always in-bounds. |
2402 | 0 | let (init, tail) = source.split_at(self.len()); |
2403 | | |
2404 | | // reuse the contained values' allocations/resources. |
2405 | 0 | self.clone_from_slice(init); |
2406 | 0 | self.extend(tail.iter().cloned()); |
2407 | 0 | } |
2408 | | } |
2409 | | |
2410 | | impl<A: Array, B: Array> PartialEq<SmallVec<B>> for SmallVec<A> |
2411 | | where |
2412 | | A::Item: PartialEq<B::Item>, |
2413 | | { |
2414 | | #[inline] |
2415 | 1.04M | fn eq(&self, other: &SmallVec<B>) -> bool { |
2416 | 1.04M | self[..] == other[..] |
2417 | 1.04M | } Unexecuted instantiation: <smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::cmp::PartialEq>::eq Unexecuted instantiation: <smallvec::SmallVec<[u8; 16]> as core::cmp::PartialEq>::eq <smallvec::SmallVec<[u8; 24]> as core::cmp::PartialEq>::eq Line | Count | Source | 2415 | 1.04M | fn eq(&self, other: &SmallVec<B>) -> bool { | 2416 | 1.04M | self[..] == other[..] | 2417 | 1.04M | } |
Unexecuted instantiation: <smallvec::SmallVec<_> as core::cmp::PartialEq<smallvec::SmallVec<_>>>::eq |
2418 | | } |
2419 | | |
2420 | | impl<A: Array> Eq for SmallVec<A> where A::Item: Eq {} |
2421 | | |
2422 | | impl<A: Array> PartialOrd for SmallVec<A> |
2423 | | where |
2424 | | A::Item: PartialOrd, |
2425 | | { |
2426 | | #[inline] |
2427 | 51.9k | fn partial_cmp(&self, other: &SmallVec<A>) -> Option<cmp::Ordering> { |
2428 | 51.9k | PartialOrd::partial_cmp(&**self, &**other) |
2429 | 51.9k | } <smallvec::SmallVec<[u8; 24]> as core::cmp::PartialOrd>::partial_cmp Line | Count | Source | 2427 | 51.9k | fn partial_cmp(&self, other: &SmallVec<A>) -> Option<cmp::Ordering> { | 2428 | 51.9k | PartialOrd::partial_cmp(&**self, &**other) | 2429 | 51.9k | } |
Unexecuted instantiation: <smallvec::SmallVec<_> as core::cmp::PartialOrd>::partial_cmp |
2430 | | } |
2431 | | |
2432 | | impl<A: Array> Ord for SmallVec<A> |
2433 | | where |
2434 | | A::Item: Ord, |
2435 | | { |
2436 | | #[inline] |
2437 | 0 | fn cmp(&self, other: &SmallVec<A>) -> cmp::Ordering { |
2438 | 0 | Ord::cmp(&**self, &**other) |
2439 | 0 | } |
2440 | | } |
2441 | | |
2442 | | impl<A: Array> Hash for SmallVec<A> |
2443 | | where |
2444 | | A::Item: Hash, |
2445 | | { |
2446 | 2.17M | fn hash<H: Hasher>(&self, state: &mut H) { |
2447 | 2.17M | (**self).hash(state) |
2448 | 2.17M | } <smallvec::SmallVec<[u8; 24]> as core::hash::Hash>::hash::<std::hash::random::DefaultHasher> Line | Count | Source | 2446 | 2.17M | fn hash<H: Hasher>(&self, state: &mut H) { | 2447 | 2.17M | (**self).hash(state) | 2448 | 2.17M | } |
Unexecuted instantiation: <smallvec::SmallVec<_> as core::hash::Hash>::hash::<_> |
2449 | | } |
2450 | | |
2451 | | unsafe impl<A: Array> Send for SmallVec<A> where A::Item: Send {} |
2452 | | |
2453 | | /// An iterator that consumes a `SmallVec` and yields its items by value. |
2454 | | /// |
2455 | | /// Returned from [`SmallVec::into_iter`][1]. |
2456 | | /// |
2457 | | /// [1]: struct.SmallVec.html#method.into_iter |
2458 | | pub struct IntoIter<A: Array> { |
2459 | | data: SmallVec<A>, |
2460 | | current: usize, |
2461 | | end: usize, |
2462 | | } |
2463 | | |
2464 | | impl<A: Array> fmt::Debug for IntoIter<A> |
2465 | | where |
2466 | | A::Item: fmt::Debug, |
2467 | | { |
2468 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
2469 | 0 | f.debug_tuple("IntoIter").field(&self.as_slice()).finish() |
2470 | 0 | } |
2471 | | } |
2472 | | |
2473 | | impl<A: Array + Clone> Clone for IntoIter<A> |
2474 | | where |
2475 | | A::Item: Clone, |
2476 | | { |
2477 | 0 | fn clone(&self) -> IntoIter<A> { |
2478 | 0 | SmallVec::from(self.as_slice()).into_iter() |
2479 | 0 | } |
2480 | | } |
2481 | | |
2482 | | impl<A: Array> Drop for IntoIter<A> { |
2483 | 95 | fn drop(&mut self) { |
2484 | 95 | for _ in self {} |
2485 | 95 | } Unexecuted instantiation: <smallvec::IntoIter<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]> as core::ops::drop::Drop>::drop Unexecuted instantiation: <smallvec::IntoIter<[exr::compression::piz::ChannelData; 6]> as core::ops::drop::Drop>::drop Unexecuted instantiation: <smallvec::IntoIter<_> as core::ops::drop::Drop>::drop Unexecuted instantiation: <smallvec::IntoIter<[alloc::vec::Vec<u64>; 3]> as core::ops::drop::Drop>::drop <smallvec::IntoIter<[alloc::vec::Vec<u64>; 3]> as core::ops::drop::Drop>::drop Line | Count | Source | 2483 | 95 | fn drop(&mut self) { | 2484 | 95 | for _ in self {} | 2485 | 95 | } |
|
2486 | | } |
2487 | | |
2488 | | impl<A: Array> Iterator for IntoIter<A> { |
2489 | | type Item = A::Item; |
2490 | | |
2491 | | #[inline] |
2492 | 285 | fn next(&mut self) -> Option<A::Item> { |
2493 | 285 | if self.current == self.end { |
2494 | 190 | None |
2495 | | } else { |
2496 | | unsafe { |
2497 | 95 | let current = self.current; |
2498 | 95 | self.current += 1; |
2499 | 95 | Some(ptr::read(self.data.as_ptr().add(current))) |
2500 | | } |
2501 | | } |
2502 | 285 | } Unexecuted instantiation: <smallvec::IntoIter<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <smallvec::IntoIter<[exr::compression::piz::ChannelData; 6]> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <smallvec::IntoIter<_> as core::iter::traits::iterator::Iterator>::next Unexecuted instantiation: <smallvec::IntoIter<[alloc::vec::Vec<u64>; 3]> as core::iter::traits::iterator::Iterator>::next <smallvec::IntoIter<[alloc::vec::Vec<u64>; 3]> as core::iter::traits::iterator::Iterator>::next Line | Count | Source | 2492 | 285 | fn next(&mut self) -> Option<A::Item> { | 2493 | 285 | if self.current == self.end { | 2494 | 190 | None | 2495 | | } else { | 2496 | | unsafe { | 2497 | 95 | let current = self.current; | 2498 | 95 | self.current += 1; | 2499 | 95 | Some(ptr::read(self.data.as_ptr().add(current))) | 2500 | | } | 2501 | | } | 2502 | 285 | } |
|
2503 | | |
2504 | | #[inline] |
2505 | 0 | fn size_hint(&self) -> (usize, Option<usize>) { |
2506 | 0 | let size = self.end - self.current; |
2507 | 0 | (size, Some(size)) |
2508 | 0 | } Unexecuted instantiation: <smallvec::IntoIter<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]> as core::iter::traits::iterator::Iterator>::size_hint Unexecuted instantiation: <smallvec::IntoIter<_> as core::iter::traits::iterator::Iterator>::size_hint |
2509 | | } |
2510 | | |
2511 | | impl<A: Array> DoubleEndedIterator for IntoIter<A> { |
2512 | | #[inline] |
2513 | 0 | fn next_back(&mut self) -> Option<A::Item> { |
2514 | 0 | if self.current == self.end { |
2515 | 0 | None |
2516 | | } else { |
2517 | | unsafe { |
2518 | 0 | self.end -= 1; |
2519 | 0 | Some(ptr::read(self.data.as_ptr().add(self.end))) |
2520 | | } |
2521 | | } |
2522 | 0 | } |
2523 | | } |
2524 | | |
2525 | | impl<A: Array> ExactSizeIterator for IntoIter<A> {} |
2526 | | impl<A: Array> FusedIterator for IntoIter<A> {} |
2527 | | |
2528 | | impl<A: Array> IntoIter<A> { |
2529 | | /// Returns the remaining items of this iterator as a slice. |
2530 | 0 | pub fn as_slice(&self) -> &[A::Item] { |
2531 | 0 | let len = self.end - self.current; |
2532 | 0 | unsafe { core::slice::from_raw_parts(self.data.as_ptr().add(self.current), len) } |
2533 | 0 | } |
2534 | | |
2535 | | /// Returns the remaining items of this iterator as a mutable slice. |
2536 | 0 | pub fn as_mut_slice(&mut self) -> &mut [A::Item] { |
2537 | 0 | let len = self.end - self.current; |
2538 | 0 | unsafe { core::slice::from_raw_parts_mut(self.data.as_mut_ptr().add(self.current), len) } |
2539 | 0 | } |
2540 | | } |
2541 | | |
2542 | | impl<A: Array> IntoIterator for SmallVec<A> { |
2543 | | type IntoIter = IntoIter<A>; |
2544 | | type Item = A::Item; |
2545 | 95 | fn into_iter(mut self) -> Self::IntoIter { |
2546 | | unsafe { |
2547 | | // Set SmallVec len to zero as `IntoIter` drop handles dropping of |
2548 | | // the elements |
2549 | 95 | let len = self.len(); |
2550 | 95 | self.set_len(0); |
2551 | 95 | IntoIter { |
2552 | 95 | data: self, |
2553 | 95 | current: 0, |
2554 | 95 | end: len, |
2555 | 95 | } |
2556 | | } |
2557 | 95 | } Unexecuted instantiation: <smallvec::SmallVec<[exr::image::AnyChannel<exr::image::FlatSamples>; 4]> as core::iter::traits::collect::IntoIterator>::into_iter Unexecuted instantiation: <smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]> as core::iter::traits::collect::IntoIterator>::into_iter Unexecuted instantiation: <smallvec::SmallVec<_> as core::iter::traits::collect::IntoIterator>::into_iter Unexecuted instantiation: <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::iter::traits::collect::IntoIterator>::into_iter <smallvec::SmallVec<[alloc::vec::Vec<u64>; 3]> as core::iter::traits::collect::IntoIterator>::into_iter Line | Count | Source | 2545 | 95 | fn into_iter(mut self) -> Self::IntoIter { | 2546 | | unsafe { | 2547 | | // Set SmallVec len to zero as `IntoIter` drop handles dropping of | 2548 | | // the elements | 2549 | 95 | let len = self.len(); | 2550 | 95 | self.set_len(0); | 2551 | 95 | IntoIter { | 2552 | 95 | data: self, | 2553 | 95 | current: 0, | 2554 | 95 | end: len, | 2555 | 95 | } | 2556 | | } | 2557 | 95 | } |
|
2558 | | } |
2559 | | |
2560 | | impl<'a, A: Array> IntoIterator for &'a SmallVec<A> { |
2561 | | type IntoIter = slice::Iter<'a, A::Item>; |
2562 | | type Item = &'a A::Item; |
2563 | 8.04k | fn into_iter(self) -> Self::IntoIter { |
2564 | 8.04k | self.iter() |
2565 | 8.04k | } Unexecuted instantiation: <&smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]> as core::iter::traits::collect::IntoIterator>::into_iter <&smallvec::SmallVec<[exr::meta::attribute::ChannelDescription; 5]> as core::iter::traits::collect::IntoIterator>::into_iter Line | Count | Source | 2563 | 237 | fn into_iter(self) -> Self::IntoIter { | 2564 | 237 | self.iter() | 2565 | 237 | } |
<&smallvec::SmallVec<[u8; 24]> as core::iter::traits::collect::IntoIterator>::into_iter Line | Count | Source | 2563 | 7.80k | fn into_iter(self) -> Self::IntoIter { | 2564 | 7.80k | self.iter() | 2565 | 7.80k | } |
Unexecuted instantiation: <&smallvec::SmallVec<_> as core::iter::traits::collect::IntoIterator>::into_iter |
2566 | | } |
2567 | | |
2568 | | impl<'a, A: Array> IntoIterator for &'a mut SmallVec<A> { |
2569 | | type IntoIter = slice::IterMut<'a, A::Item>; |
2570 | | type Item = &'a mut A::Item; |
2571 | 0 | fn into_iter(self) -> Self::IntoIter { |
2572 | 0 | self.iter_mut() |
2573 | 0 | } Unexecuted instantiation: <&mut smallvec::SmallVec<[exr::compression::piz::ChannelData; 6]> as core::iter::traits::collect::IntoIterator>::into_iter Unexecuted instantiation: <&mut smallvec::SmallVec<_> as core::iter::traits::collect::IntoIterator>::into_iter |
2574 | | } |
2575 | | |
2576 | | /// Types that can be used as the backing store for a [`SmallVec`]. |
2577 | | pub unsafe trait Array { |
2578 | | /// The type of the array's elements. |
2579 | | type Item; |
2580 | | /// Returns the number of items the array can hold. |
2581 | | fn size() -> usize; |
2582 | | } |
2583 | | |
2584 | | /// Set the length of the vec when the `SetLenOnDrop` value goes out of scope. |
2585 | | /// |
2586 | | /// Copied from <https://github.com/rust-lang/rust/pull/36355> |
2587 | | struct SetLenOnDrop<'a> { |
2588 | | len: &'a mut usize, |
2589 | | local_len: usize, |
2590 | | } |
2591 | | |
2592 | | impl<'a> SetLenOnDrop<'a> { |
2593 | | #[inline] |
2594 | 9.49M | fn new(len: &'a mut usize) -> Self { |
2595 | 9.49M | SetLenOnDrop { |
2596 | 9.49M | local_len: *len, |
2597 | 9.49M | len, |
2598 | 9.49M | } |
2599 | 9.49M | } <smallvec::SetLenOnDrop>::new Line | Count | Source | 2594 | 4.52M | fn new(len: &'a mut usize) -> Self { | 2595 | 4.52M | SetLenOnDrop { | 2596 | 4.52M | local_len: *len, | 2597 | 4.52M | len, | 2598 | 4.52M | } | 2599 | 4.52M | } |
<smallvec::SetLenOnDrop>::new Line | Count | Source | 2594 | 4.96M | fn new(len: &'a mut usize) -> Self { | 2595 | 4.96M | SetLenOnDrop { | 2596 | 4.96M | local_len: *len, | 2597 | 4.96M | len, | 2598 | 4.96M | } | 2599 | 4.96M | } |
Unexecuted instantiation: <smallvec::SetLenOnDrop>::new Unexecuted instantiation: <smallvec::SetLenOnDrop>::new <smallvec::SetLenOnDrop>::new Line | Count | Source | 2594 | 190 | fn new(len: &'a mut usize) -> Self { | 2595 | 190 | SetLenOnDrop { | 2596 | 190 | local_len: *len, | 2597 | 190 | len, | 2598 | 190 | } | 2599 | 190 | } |
|
2600 | | |
2601 | | #[inline] |
2602 | 152M | fn get(&self) -> usize { |
2603 | 152M | self.local_len |
2604 | 152M | } <smallvec::SetLenOnDrop>::get Line | Count | Source | 2602 | 112M | fn get(&self) -> usize { | 2603 | 112M | self.local_len | 2604 | 112M | } |
<smallvec::SetLenOnDrop>::get Line | Count | Source | 2602 | 40.1M | fn get(&self) -> usize { | 2603 | 40.1M | self.local_len | 2604 | 40.1M | } |
Unexecuted instantiation: <smallvec::SetLenOnDrop>::get Unexecuted instantiation: <smallvec::SetLenOnDrop>::get <smallvec::SetLenOnDrop>::get Line | Count | Source | 2602 | 570 | fn get(&self) -> usize { | 2603 | 570 | self.local_len | 2604 | 570 | } |
|
2605 | | |
2606 | | #[inline] |
2607 | 71.5M | fn increment_len(&mut self, increment: usize) { |
2608 | 71.5M | self.local_len += increment; |
2609 | 71.5M | } <smallvec::SetLenOnDrop>::increment_len Line | Count | Source | 2607 | 53.9M | fn increment_len(&mut self, increment: usize) { | 2608 | 53.9M | self.local_len += increment; | 2609 | 53.9M | } |
<smallvec::SetLenOnDrop>::increment_len Line | Count | Source | 2607 | 17.5M | fn increment_len(&mut self, increment: usize) { | 2608 | 17.5M | self.local_len += increment; | 2609 | 17.5M | } |
Unexecuted instantiation: <smallvec::SetLenOnDrop>::increment_len Unexecuted instantiation: <smallvec::SetLenOnDrop>::increment_len <smallvec::SetLenOnDrop>::increment_len Line | Count | Source | 2607 | 190 | fn increment_len(&mut self, increment: usize) { | 2608 | 190 | self.local_len += increment; | 2609 | 190 | } |
|
2610 | | } |
2611 | | |
2612 | | impl<'a> Drop for SetLenOnDrop<'a> { |
2613 | | #[inline] |
2614 | 9.49M | fn drop(&mut self) { |
2615 | 9.49M | *self.len = self.local_len; |
2616 | 9.49M | } <smallvec::SetLenOnDrop as core::ops::drop::Drop>::drop Line | Count | Source | 2614 | 9.49M | fn drop(&mut self) { | 2615 | 9.49M | *self.len = self.local_len; | 2616 | 9.49M | } |
Unexecuted instantiation: <smallvec::SetLenOnDrop as core::ops::drop::Drop>::drop |
2617 | | } |
2618 | | |
2619 | | #[cfg(feature = "const_new")] |
2620 | | impl<T, const N: usize> SmallVec<[T; N]> { |
2621 | | /// Construct an empty vector. |
2622 | | /// |
2623 | | /// This is a `const` version of [`SmallVec::new`] that is enabled by the |
2624 | | /// feature `const_new`, with the limitation that it only works for arrays. |
2625 | | #[cfg_attr(docsrs, doc(cfg(feature = "const_new")))] |
2626 | | #[inline] |
2627 | | pub const fn new_const() -> Self { |
2628 | | SmallVec { |
2629 | | capacity: 0, |
2630 | | data: SmallVecData::from_const(MaybeUninit::uninit()), |
2631 | | _marker: PhantomData, |
2632 | | } |
2633 | | } |
2634 | | |
2635 | | /// The array passed as an argument is moved to be an inline version of |
2636 | | /// `SmallVec`. |
2637 | | /// |
2638 | | /// This is a `const` version of [`SmallVec::from_buf`] that is enabled by |
2639 | | /// the feature `const_new`, with the limitation that it only works for |
2640 | | /// arrays. |
2641 | | #[cfg_attr(docsrs, doc(cfg(feature = "const_new")))] |
2642 | | #[inline] |
2643 | | pub const fn from_const(items: [T; N]) -> Self { |
2644 | | SmallVec { |
2645 | | capacity: N, |
2646 | | data: SmallVecData::from_const(MaybeUninit::new(items)), |
2647 | | _marker: PhantomData, |
2648 | | } |
2649 | | } |
2650 | | |
2651 | | /// Constructs a new `SmallVec` on the stack from an array without |
2652 | | /// copying elements. Also sets the length. The user is responsible |
2653 | | /// for ensuring that `len <= N`. |
2654 | | /// |
2655 | | /// This is a `const` version of [`SmallVec::from_buf_and_len_unchecked`] |
2656 | | /// that is enabled by the feature `const_new`, with the limitation that it |
2657 | | /// only works for arrays. |
2658 | | #[cfg_attr(docsrs, doc(cfg(feature = "const_new")))] |
2659 | | #[inline] |
2660 | | pub const unsafe fn from_const_with_len_unchecked(items: [T; N], len: usize) -> Self { |
2661 | | SmallVec { |
2662 | | capacity: len, |
2663 | | data: SmallVecData::from_const(MaybeUninit::new(items)), |
2664 | | _marker: PhantomData, |
2665 | | } |
2666 | | } |
2667 | | } |
2668 | | |
2669 | | #[cfg(feature = "const_generics")] |
2670 | | #[cfg_attr(docsrs, doc(cfg(feature = "const_generics")))] |
2671 | | unsafe impl<T, const N: usize> Array for [T; N] { |
2672 | | type Item = T; |
2673 | | #[inline] |
2674 | | fn size() -> usize { |
2675 | | N |
2676 | | } |
2677 | | } |
2678 | | |
2679 | | #[cfg(not(feature = "const_generics"))] |
2680 | | macro_rules! impl_array( |
2681 | | ($($size:expr),+) => { |
2682 | | $( |
2683 | | unsafe impl<T> Array for [T; $size] { |
2684 | | type Item = T; |
2685 | | #[inline] |
2686 | 309M | fn size() -> usize { $size }<[u8; 64] as smallvec::Array>::size Line | Count | Source | 2686 | 38.0M | fn size() -> usize { $size } |
<[alloc::vec::Vec<u64>; 3] as smallvec::Array>::size Line | Count | Source | 2686 | 5.08M | fn size() -> usize { $size } |
<[u8; 8] as smallvec::Array>::size Line | Count | Source | 2686 | 237k | fn size() -> usize { $size } |
Unexecuted instantiation: <[usize; 8] as smallvec::Array>::size <[u8; 16] as smallvec::Array>::size Line | Count | Source | 2686 | 8.82M | fn size() -> usize { $size } |
<[u8; 24] as smallvec::Array>::size Line | Count | Source | 2686 | 227M | fn size() -> usize { $size } |
<[u32; 2] as smallvec::Array>::size Line | Count | Source | 2686 | 17.8k | fn size() -> usize { $size } |
Unexecuted instantiation: <[exr::image::AnyChannel<exr::image::FlatSamples>; 4] as smallvec::Array>::size <[exr::meta::attribute::ChannelDescription; 5] as smallvec::Array>::size Line | Count | Source | 2686 | 10.2M | fn size() -> usize { $size } |
Unexecuted instantiation: <[exr::block::samples::Sample; 8] as smallvec::Array>::size Unexecuted instantiation: <[exr::compression::piz::ChannelData; 6] as smallvec::Array>::size <[exr::meta::header::Header; 3] as smallvec::Array>::size Line | Count | Source | 2686 | 19.3M | fn size() -> usize { $size } |
Unexecuted instantiation: <[_; 5] as smallvec::Array>::size Unexecuted instantiation: <[_; 6] as smallvec::Array>::size Unexecuted instantiation: <[_; 7] as smallvec::Array>::size Unexecuted instantiation: <[_; 8] as smallvec::Array>::size Unexecuted instantiation: <[_; 9] as smallvec::Array>::size Unexecuted instantiation: <[_; 10] as smallvec::Array>::size Unexecuted instantiation: <[_; 11] as smallvec::Array>::size Unexecuted instantiation: <[_; 12] as smallvec::Array>::size Unexecuted instantiation: <[_; 13] as smallvec::Array>::size Unexecuted instantiation: <[_; 14] as smallvec::Array>::size Unexecuted instantiation: <[_; 2048] as smallvec::Array>::size Unexecuted instantiation: <[_; 4096] as smallvec::Array>::size Unexecuted instantiation: <[_; 8192] as smallvec::Array>::size Unexecuted instantiation: <[_; 16384] as smallvec::Array>::size Unexecuted instantiation: <[_; 24576] as smallvec::Array>::size Unexecuted instantiation: <[_; 32768] as smallvec::Array>::size Unexecuted instantiation: <[_; 65536] as smallvec::Array>::size Unexecuted instantiation: <[_; 131072] as smallvec::Array>::size Unexecuted instantiation: <[_; 262144] as smallvec::Array>::size Unexecuted instantiation: <[_; 393216] as smallvec::Array>::size Unexecuted instantiation: <[_; 524288] as smallvec::Array>::size Unexecuted instantiation: <[_; 1048576] as smallvec::Array>::size Unexecuted instantiation: <[_; 15] as smallvec::Array>::size Unexecuted instantiation: <[_; 16] as smallvec::Array>::size Unexecuted instantiation: <[_; 17] as smallvec::Array>::size Unexecuted instantiation: <[_; 18] as smallvec::Array>::size Unexecuted instantiation: <[_; 19] as smallvec::Array>::size Unexecuted instantiation: <[_; 20] as smallvec::Array>::size Unexecuted instantiation: <[_; 21] as smallvec::Array>::size Unexecuted instantiation: <[_; 22] as smallvec::Array>::size Unexecuted instantiation: <[_; 23] as smallvec::Array>::size Unexecuted instantiation: <[_; 24] as smallvec::Array>::size Unexecuted instantiation: <[_; 25] as smallvec::Array>::size Unexecuted instantiation: <[_; 26] as smallvec::Array>::size Unexecuted instantiation: <[_; 27] as smallvec::Array>::size Unexecuted instantiation: <[_; 28] as smallvec::Array>::size Unexecuted instantiation: <[_; 29] as smallvec::Array>::size Unexecuted instantiation: <[_; 30] as smallvec::Array>::size Unexecuted instantiation: <[_; 31] as smallvec::Array>::size Unexecuted instantiation: <[_; 32] as smallvec::Array>::size Unexecuted instantiation: <[_; 36] as smallvec::Array>::size Unexecuted instantiation: <[_; 64] as smallvec::Array>::size Unexecuted instantiation: <[_; 96] as smallvec::Array>::size Unexecuted instantiation: <[_; 128] as smallvec::Array>::size Unexecuted instantiation: <[_; 256] as smallvec::Array>::size Unexecuted instantiation: <[_; 512] as smallvec::Array>::size Unexecuted instantiation: <[_; 1024] as smallvec::Array>::size Unexecuted instantiation: <[_; 1536] as smallvec::Array>::size Unexecuted instantiation: <[_; 0] as smallvec::Array>::size Unexecuted instantiation: <[_; 1] as smallvec::Array>::size Unexecuted instantiation: <[_; 2] as smallvec::Array>::size Unexecuted instantiation: <[_; 3] as smallvec::Array>::size Unexecuted instantiation: <[_; 4] as smallvec::Array>::size |
2687 | | } |
2688 | | )+ |
2689 | | } |
2690 | | ); |
2691 | | |
2692 | | #[cfg(not(feature = "const_generics"))] |
2693 | | impl_array!( |
2694 | | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, |
2695 | | 26, 27, 28, 29, 30, 31, 32, 36, 0x40, 0x60, 0x80, 0x100, 0x200, 0x400, 0x600, 0x800, 0x1000, |
2696 | | 0x2000, 0x4000, 0x6000, 0x8000, 0x10000, 0x20000, 0x40000, 0x60000, 0x80000, 0x10_0000 |
2697 | | ); |
2698 | | |
2699 | | /// Convenience trait for constructing a `SmallVec` |
2700 | | pub trait ToSmallVec<A: Array> { |
2701 | | /// Construct a new `SmallVec` from a slice. |
2702 | | fn to_smallvec(&self) -> SmallVec<A>; |
2703 | | } |
2704 | | |
2705 | | impl<A: Array> ToSmallVec<A> for [A::Item] |
2706 | | where |
2707 | | A::Item: Copy, |
2708 | | { |
2709 | | #[inline] |
2710 | 0 | fn to_smallvec(&self) -> SmallVec<A> { |
2711 | 0 | SmallVec::from_slice(self) |
2712 | 0 | } |
2713 | | } |
2714 | | |
2715 | | // Immutable counterpart for `NonNull<T>`. |
2716 | | #[repr(transparent)] |
2717 | | struct ConstNonNull<T>(NonNull<T>); |
2718 | | |
2719 | | impl<T> ConstNonNull<T> { |
2720 | | #[inline] |
2721 | 61.1M | fn new(ptr: *const T) -> Option<Self> { |
2722 | 61.1M | NonNull::new(ptr as *mut T).map(Self) |
2723 | 61.1M | } Unexecuted instantiation: <smallvec::ConstNonNull<exr::image::AnyChannel<exr::image::FlatSamples>>>::new <smallvec::ConstNonNull<alloc::vec::Vec<u64>>>::new Line | Count | Source | 2721 | 1.63M | fn new(ptr: *const T) -> Option<Self> { | 2722 | 1.63M | NonNull::new(ptr as *mut T).map(Self) | 2723 | 1.63M | } |
Unexecuted instantiation: <smallvec::ConstNonNull<exr::compression::piz::ChannelData>>::new <smallvec::ConstNonNull<exr::meta::header::Header>>::new Line | Count | Source | 2721 | 6.14M | fn new(ptr: *const T) -> Option<Self> { | 2722 | 6.14M | NonNull::new(ptr as *mut T).map(Self) | 2723 | 6.14M | } |
<smallvec::ConstNonNull<exr::meta::attribute::ChannelDescription>>::new Line | Count | Source | 2721 | 1.20M | fn new(ptr: *const T) -> Option<Self> { | 2722 | 1.20M | NonNull::new(ptr as *mut T).map(Self) | 2723 | 1.20M | } |
Unexecuted instantiation: <smallvec::ConstNonNull<exr::block::samples::Sample>>::new <smallvec::ConstNonNull<u8>>::new Line | Count | Source | 2721 | 52.1M | fn new(ptr: *const T) -> Option<Self> { | 2722 | 52.1M | NonNull::new(ptr as *mut T).map(Self) | 2723 | 52.1M | } |
Unexecuted instantiation: <smallvec::ConstNonNull<usize>>::new <smallvec::ConstNonNull<u32>>::new Line | Count | Source | 2721 | 1.07k | fn new(ptr: *const T) -> Option<Self> { | 2722 | 1.07k | NonNull::new(ptr as *mut T).map(Self) | 2723 | 1.07k | } |
Unexecuted instantiation: <smallvec::ConstNonNull<_>>::new |
2724 | | #[inline] |
2725 | 23.7M | fn as_ptr(self) -> *const T { |
2726 | 23.7M | self.0.as_ptr() |
2727 | 23.7M | } Unexecuted instantiation: <smallvec::ConstNonNull<exr::image::AnyChannel<exr::image::FlatSamples>>>::as_ptr <smallvec::ConstNonNull<alloc::vec::Vec<u64>>>::as_ptr Line | Count | Source | 2725 | 1.67M | fn as_ptr(self) -> *const T { | 2726 | 1.67M | self.0.as_ptr() | 2727 | 1.67M | } |
Unexecuted instantiation: <smallvec::ConstNonNull<exr::compression::piz::ChannelData>>::as_ptr <smallvec::ConstNonNull<exr::meta::header::Header>>::as_ptr Line | Count | Source | 2725 | 5.27M | fn as_ptr(self) -> *const T { | 2726 | 5.27M | self.0.as_ptr() | 2727 | 5.27M | } |
<smallvec::ConstNonNull<exr::meta::attribute::ChannelDescription>>::as_ptr Line | Count | Source | 2725 | 1.20M | fn as_ptr(self) -> *const T { | 2726 | 1.20M | self.0.as_ptr() | 2727 | 1.20M | } |
<smallvec::ConstNonNull<u8>>::as_ptr Line | Count | Source | 2725 | 15.6M | fn as_ptr(self) -> *const T { | 2726 | 15.6M | self.0.as_ptr() | 2727 | 15.6M | } |
Unexecuted instantiation: <smallvec::ConstNonNull<usize>>::as_ptr <smallvec::ConstNonNull<u32>>::as_ptr Line | Count | Source | 2725 | 12.1k | fn as_ptr(self) -> *const T { | 2726 | 12.1k | self.0.as_ptr() | 2727 | 12.1k | } |
Unexecuted instantiation: <smallvec::ConstNonNull<_>>::as_ptr |
2728 | | } |
2729 | | |
2730 | | impl<T> Clone for ConstNonNull<T> { |
2731 | | #[inline] |
2732 | 0 | fn clone(&self) -> Self { |
2733 | 0 | *self |
2734 | 0 | } |
2735 | | } |
2736 | | |
2737 | | impl<T> Copy for ConstNonNull<T> {} |
2738 | | |
2739 | | #[cfg(feature = "impl_bincode")] |
2740 | | use bincode::{ |
2741 | | de::{read::Reader, BorrowDecoder, Decode, Decoder}, |
2742 | | enc::{write::Writer, Encode, Encoder}, |
2743 | | error::{DecodeError, EncodeError}, |
2744 | | BorrowDecode, |
2745 | | }; |
2746 | | |
2747 | | #[cfg(feature = "impl_bincode")] |
2748 | | impl<A, Context> Decode<Context> for SmallVec<A> |
2749 | | where |
2750 | | A: Array, |
2751 | | A::Item: Decode<Context>, |
2752 | | { |
2753 | | fn decode<D: Decoder<Context = Context>>(decoder: &mut D) -> Result<Self, DecodeError> { |
2754 | | use core::convert::TryInto; |
2755 | | let len = u64::decode(decoder)?; |
2756 | | let len = len |
2757 | | .try_into() |
2758 | | .map_err(|_| DecodeError::OutsideUsizeRange(len))?; |
2759 | | decoder.claim_container_read::<A::Item>(len)?; |
2760 | | |
2761 | | let mut vec = SmallVec::with_capacity(len); |
2762 | | if unty::type_equal::<A::Item, u8>() { |
2763 | | // Initialize the smallvec's buffer. Note that we need to do this |
2764 | | // through the raw pointer as we cannot name the type |
2765 | | // [u8; N] even though A::Item is u8. |
2766 | | let ptr = vec.as_mut_ptr(); |
2767 | | // SAFETY: A::Item is u8 and the smallvec has been allocated with |
2768 | | // enough capacity |
2769 | | unsafe { |
2770 | | core::ptr::write_bytes(ptr, 0, len); |
2771 | | vec.set_len(len); |
2772 | | } |
2773 | | // Read the data into the smallvec's buffer. |
2774 | | let slice = vec.as_mut_slice(); |
2775 | | // SAFETY: A::Item is u8 |
2776 | | let slice = unsafe { core::mem::transmute::<&mut [A::Item], &mut [u8]>(slice) }; |
2777 | | decoder.reader().read(slice)?; |
2778 | | } else { |
2779 | | for _ in 0..len { |
2780 | | decoder.unclaim_bytes_read(core::mem::size_of::<A::Item>()); |
2781 | | vec.push(A::Item::decode(decoder)?); |
2782 | | } |
2783 | | } |
2784 | | Ok(vec) |
2785 | | } |
2786 | | } |
2787 | | |
2788 | | #[cfg(feature = "impl_bincode")] |
2789 | | impl<'de, A, Context> BorrowDecode<'de, Context> for SmallVec<A> |
2790 | | where |
2791 | | A: Array, |
2792 | | A::Item: BorrowDecode<'de, Context>, |
2793 | | { |
2794 | | fn borrow_decode<D: BorrowDecoder<'de, Context = Context>>( |
2795 | | decoder: &mut D, |
2796 | | ) -> Result<Self, DecodeError> { |
2797 | | use core::convert::TryInto; |
2798 | | let len = u64::decode(decoder)?; |
2799 | | let len = len |
2800 | | .try_into() |
2801 | | .map_err(|_| DecodeError::OutsideUsizeRange(len))?; |
2802 | | decoder.claim_container_read::<A::Item>(len)?; |
2803 | | |
2804 | | let mut vec = SmallVec::with_capacity(len); |
2805 | | if unty::type_equal::<A::Item, u8>() { |
2806 | | // Initialize the smallvec's buffer. Note that we need to do this |
2807 | | // through the raw pointer as we cannot name the type |
2808 | | // [u8; N] even though A::Item is u8. |
2809 | | let ptr = vec.as_mut_ptr(); |
2810 | | // SAFETY: A::Item is u8 and the smallvec has been allocated with |
2811 | | // enough capacity |
2812 | | unsafe { |
2813 | | core::ptr::write_bytes(ptr, 0, len); |
2814 | | vec.set_len(len); |
2815 | | } |
2816 | | // Read the data into the smallvec's buffer. |
2817 | | let slice = vec.as_mut_slice(); |
2818 | | // SAFETY: A::Item is u8 |
2819 | | let slice = unsafe { core::mem::transmute::<&mut [A::Item], &mut [u8]>(slice) }; |
2820 | | decoder.reader().read(slice)?; |
2821 | | } else { |
2822 | | for _ in 0..len { |
2823 | | decoder.unclaim_bytes_read(core::mem::size_of::<A::Item>()); |
2824 | | vec.push(A::Item::borrow_decode(decoder)?); |
2825 | | } |
2826 | | } |
2827 | | Ok(vec) |
2828 | | } |
2829 | | } |
2830 | | |
2831 | | #[cfg(feature = "impl_bincode")] |
2832 | | impl<A> Encode for SmallVec<A> |
2833 | | where |
2834 | | A: Array, |
2835 | | A::Item: Encode, |
2836 | | { |
2837 | | fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError> { |
2838 | | (self.len() as u64).encode(encoder)?; |
2839 | | if unty::type_equal::<A::Item, u8>() { |
2840 | | // Safety: A::Item is u8 |
2841 | | let slice: &[u8] = unsafe { core::mem::transmute(self.as_slice()) }; |
2842 | | encoder.writer().write(slice)?; |
2843 | | } else { |
2844 | | for item in self.iter() { |
2845 | | item.encode(encoder)?; |
2846 | | } |
2847 | | } |
2848 | | Ok(()) |
2849 | | } |
2850 | | } |