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

Quelle  pending.rs

  Sprache: Rust
 

use core::marker::PhantomData;

use crate::allocate::Allocator;

pub struct Pending<'a> {
    buf: *mut u8,
    out: *mut u8,
    pub(crate) pending: usize,
    end: *mut u8,
    _marker: PhantomData<&'a mut [u8]>,
}

impl<'a> Pending<'a> {
    pub fn reset_keep(&mut self) {
        // keep the buffer as it is
        self.pending = 0;
    }

    pub fn pending(&self) -> &[u8] {
        unsafe { core::slice::from_raw_parts(self.out, self.pending) }
    }

    pub(cratefn remaining(&self) -> usize {
        self.end as usize - self.out as usize
    }

    pub(cratefn capacity(&self) -> usize {
        self.end as usize - self.buf as usize
    }

    #[inline(always)]
    #[track_caller]
    pub fn advance(&mut self, n: usize) {
        assert!(n <= self.remaining(), "advancing past the end");
        debug_assert!(self.pending >= n);

        self.out = self.out.wrapping_add(n);
        self.pending -= n;

        if self.pending == 0 {
            self.out = self.buf;
        }
    }

    #[inline(always)]
    #[track_caller]
    pub fn rewind(&mut self, n: usize) {
        assert!(n <= self.pending, "rewinding past then start");

        self.pending -= n;
    }

    #[inline(always)]
    #[track_caller]
    pub fn extend(&mut self, buf: &[u8]) {
        assert!(
            self.remaining() >= buf.len(),
            "buf.len() must fit in remaining()"
        );

        unsafe {
            core::ptr::copy_nonoverlapping(buf.as_ptr(), self.out.add(self.pending), buf.len());
        }

        self.pending += buf.len();
    }

    pub(cratefn new_in(alloc: &Allocator<'a>, len: usize) -> Option<Self> {
        let range = alloc.allocate_slice::<u8>(len)?.as_mut_ptr_range();

        Some(Self {
            buf: range.start as *mut u8,
            out: range.start as *mut u8,
            end: range.end as *mut u8,
            pending: 0,
            _marker: PhantomData,
        })
    }

    pub(cratefn clone_in(&self, alloc: &Allocator<'a>) -> Option<Self> {
        let len = self.end as usize - self.buf as usize;
        let mut clone = Self::new_in(alloc, len)?;

        unsafe { core::ptr::copy_nonoverlapping(self.buf, clone.buf, len) };
        clone.out = unsafe { clone.buf.add(self.out as usize - self.buf as usize) };
        clone.pending = self.pending;

        Some(clone)
    }

    pub(crateunsafe fn drop_in(&self, alloc: &Allocator) {
        let len = self.end as usize - self.buf as usize;
        alloc.deallocate(self.buf, len);
    }
}

Messung V0.5 in Prozent
C=89 H=95 G=91

¤ Dauer der Verarbeitung: 0.11 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.