Coverage Report

Created: 2026-12-01 08:10

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