Coverage Report

Created: 2026-10-28 07:17

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