Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/zerotrie/src/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 3 kB image not shown  

Quelle  helpers.rs

  Sprache: Rust
 

// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

pub(cratetrait MaybeSplitAt<T> {
    /// Like slice::split_at but debug-panics and returns an empty second slice
    /// if the index is out of range.
    fn debug_split_at(&self, mid: usize) -> (&Self, &Self);
}

impl<T> MaybeSplitAt<T> for [T] {
    #[inline]
    fn debug_split_at(&self, mid: usize) -> (&Self, &Self) {
        self.split_at_checked(mid).unwrap_or_else(|| {
            debug_assert!(false"debug_split_at: {mid} expected to be in range");
            (self, &[])
        })
    }
}

pub(cratetrait DebugUnwrapOr<T> {
    /// Unwraps the option or panics in debug mode, returning the `gigo_value`
    fn debug_unwrap_or(self, gigo_value: T) -> T;
}

impl<T> DebugUnwrapOr<T> for Option<T> {
    #[inline]
    fn debug_unwrap_or(self, gigo_value: T) -> T {
        match self {
            Some(x) => x,
            None => {
                debug_assert!(false"debug_unwrap_or called on a None value");
                gigo_value
            }
        }
    }
}

macro_rules! debug_unwrap {
    ($expr:expr, return $retval:expr, $($arg:tt)+) => {
        match $expr {
            Some(x) => x,
            None => {
                debug_assert!(false, $($arg)*);
                return $retval;
            }
        }
    };
    ($expr:expr, return $retval:expr) => {
        debug_unwrap!($expr, return $retval, "invalid trie")
    };
    ($expr:expr, break, $($arg:tt)+) => {
        match $expr {
            Some(x) => x,
            None => {
                debug_assert!(false, $($arg)*);
                break;
            }
        }
    };
    ($expr:expr, break) => {
        debug_unwrap!($expr, break"invalid trie")
    };
    ($expr:expr, $($arg:tt)+) => {
        debug_unwrap!($expr, return (), $($arg)*)
    };
    ($expr:expr) => {
        debug_unwrap!($expr, return ())
    };
}

pub(crateuse debug_unwrap;

/// The maximum number of base-10 digits required for rendering a usize.
/// Note: 24/10 is an approximation of 8*log10(2)
pub(crateconst MAX_USIZE_LEN_AS_DIGITS: usize = core::mem::size_of::<usize>() * 24 / 10 + 1;

/// Formats a usize as a string of length N, padded with spaces,
/// with the given prefix.
///
/// If the string is too short, the function may panic. To prevent
/// this, N should be MAX_USIZE_LEN_AS_DIGITS larger than M.
pub(crateconst fn const_fmt_int<const M: usize, const N: usize>(
    prefix: [u8; M],
    value: usize,
) -> [u8; N] {
    let mut output = [b' '; N];
    let mut i = 0;
    while i < M {
        output[i] = prefix[i];
        i += 1;
    }
    let mut int_only = [b' '; MAX_USIZE_LEN_AS_DIGITS];
    let mut value = value;
    let mut i = MAX_USIZE_LEN_AS_DIGITS - 1;
    loop {
        let x = (value % 10as u8;
        int_only[i] = x + b'0';
        value /= 10;
        if value == 0 {
            break;
        }
        i -= 1;
    }
    let mut j = M;
    while i < MAX_USIZE_LEN_AS_DIGITS {
        output[j] = int_only[i];
        j += 1;
        i += 1;
    }
    output
}

#[test]
fn test_const_fmt_int() {
    assert_eq!(*b"123", const_fmt_int::<03>(*b""123));
    assert_eq!(*b"123   ", const_fmt_int::<06>(*b""123));
    assert_eq!(*b"abc123", const_fmt_int::<36>(*b"abc"123));
}

Messung V0.5 in Prozent
C=66 H=96 G=82

¤ Dauer der Verarbeitung: 0.19 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.