Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/async-task/src/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 3 kB image not shown  

Quelle  utils.rs

  Sprache: Rust
 

use core::alloc::Layout as StdLayout;
use core::mem;

/// Aborts the process.
///
/// To abort, this function simply panics while panicking.
pub(cratefn abort() -> ! {
    struct Panic;

    impl Drop for Panic {
        fn drop(&mut self) {
            panic!("aborting the process");
        }
    }

    let _panic = Panic;
    panic!("aborting the process");
}

/// Calls a function and aborts if it panics.
///
/// This is useful in unsafe code where we can't recover from panics.
#[inline]
pub(cratefn abort_on_panic<T>(f: impl FnOnce() -> T) -> T {
    struct Bomb;

    impl Drop for Bomb {
        fn drop(&mut self) {
            abort();
        }
    }

    let bomb = Bomb;
    let t = f();
    mem::forget(bomb);
    t
}

/// A version of `alloc::alloc::Layout` that can be used in the const
/// position.
#[derive(Clone, Copy, Debug)]
pub(cratestruct Layout {
    size: usize,
    align: usize,
}

impl Layout {
    /// Creates a new `Layout` with the given size and alignment.
    #[inline]
    pub(crateconst fn from_size_align(size: usize, align: usize) -> Self {
        Self { size, align }
    }

    /// Creates a new `Layout` for the given sized type.
    #[inline]
    pub(crateconst fn new<T>() -> Self {
        Self::from_size_align(mem::size_of::<T>(), mem::align_of::<T>())
    }

    /// Convert this into the standard library's layout type.
    ///
    /// # Safety
    ///
    /// - `align` must be non-zero and a power of two.
    /// - When rounded up to the nearest multiple of `align`, the size
    ///   must not overflow.
    #[inline]
    pub(crateconst unsafe fn into_std(self) -> StdLayout {
        StdLayout::from_size_align_unchecked(self.size, self.align)
    }

    /// Get the alignment of this layout.
    #[inline]
    pub(crateconst fn align(&self) -> usize {
        self.align
    }

    /// Get the size of this layout.
    #[inline]
    pub(crateconst fn size(&self) -> usize {
        self.size
    }

    /// Returns the layout for `a` followed by `b` and the offset of `b`.
    ///
    /// This function was adapted from the currently unstable `Layout::extend()`:
    /// https://doc.rust-lang.org/nightly/std/alloc/struct.Layout.html#method.extend
    #[inline]
    pub(crateconst fn extend(self, other: Layout) -> Option<(Layout, usize)> {
        let new_align = max(self.align(), other.align());
        let pad = self.padding_needed_for(other.align());

        let offset = leap!(self.size().checked_add(pad));
        let new_size = leap!(offset.checked_add(other.size()));

        // return None if any of the following are true:
        // - align is 0 (implied false by is_power_of_two())
        // - align is not a power of 2
        // - size rounded up to align overflows
        if !new_align.is_power_of_two() || new_size > core::usize::MAX - (new_align - 1) {
            return None;
        }

        let layout = Layout::from_size_align(new_size, new_align);
        Some((layout, offset))
    }

    /// Returns the padding after `layout` that aligns the following address to `align`.
    ///
    /// This function was adapted from the currently unstable `Layout::padding_needed_for()`:
    /// https://doc.rust-lang.org/nightly/std/alloc/struct.Layout.html#method.padding_needed_for
    #[inline]
    pub(crateconst fn padding_needed_for(self, align: usize) -> usize {
        let len = self.size();
        let len_rounded_up = len.wrapping_add(align).wrapping_sub(1) & !align.wrapping_sub(1);
        len_rounded_up.wrapping_sub(len)
    }
}

#[inline]
pub(crateconst fn max(left: usize, right: usize) -> usize {
    if left > right {
        left
    } else {
        right
    }
}

Messung V0.5 in Prozent
C=81 H=87 G=83

¤ Dauer der Verarbeitung: 0.0 Sekunden  (vorverarbeitet am  2026-06-18) ¤

*© 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.