File: stackvec.rs

package info (click to toggle)
rust-minimal-lexical 0.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 556 kB
  • sloc: makefile: 4
file content (32 lines) | stat: -rw-r--r-- 948 bytes parent folder | download | duplicates (46)
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
26
27
28
29
30
31
32
use minimal_lexical::bigint;
#[cfg(feature = "alloc")]
pub use minimal_lexical::heapvec::HeapVec as VecType;
#[cfg(not(feature = "alloc"))]
pub use minimal_lexical::stackvec::StackVec as VecType;

pub fn vec_from_u32(x: &[u32]) -> VecType {
    let mut vec = VecType::new();
    #[cfg(not(all(target_pointer_width = "64", not(target_arch = "sparc"))))]
    {
        for &xi in x {
            vec.try_push(xi as bigint::Limb).unwrap();
        }
    }

    #[cfg(all(target_pointer_width = "64", not(target_arch = "sparc")))]
    {
        for xi in x.chunks(2) {
            match xi.len() {
                1 => vec.try_push(xi[0] as bigint::Limb).unwrap(),
                2 => {
                    let xi0 = xi[0] as bigint::Limb;
                    let xi1 = xi[1] as bigint::Limb;
                    vec.try_push((xi1 << 32) | xi0).unwrap()
                },
                _ => unreachable!(),
            }
        }
    }

    vec
}