Sha256: 1c80fa432acc23223a75a5181e37c40034764dffe42410e4b77af6f24f48bd5c

Contents?: true

Size: 1.41 KB

Versions: 30

Compression:

Stored size: 1.41 KB

Contents

use crate::util::{
    prefilter::PrefilterI,
    search::{MatchKind, Span},
};

#[derive(Clone, Debug)]
pub(crate) struct ByteSet([bool; 256]);

impl ByteSet {
    pub(crate) fn new<B: AsRef<[u8]>>(
        _kind: MatchKind,
        needles: &[B],
    ) -> Option<ByteSet> {
        #[cfg(not(feature = "perf-literal-multisubstring"))]
        {
            None
        }
        #[cfg(feature = "perf-literal-multisubstring")]
        {
            let mut set = [false; 256];
            for needle in needles.iter() {
                let needle = needle.as_ref();
                if needle.len() != 1 {
                    return None;
                }
                set[usize::from(needle[0])] = true;
            }
            Some(ByteSet(set))
        }
    }
}

impl PrefilterI for ByteSet {
    fn find(&self, haystack: &[u8], span: Span) -> Option<Span> {
        haystack[span].iter().position(|&b| self.0[usize::from(b)]).map(|i| {
            let start = span.start + i;
            let end = start + 1;
            Span { start, end }
        })
    }

    fn prefix(&self, haystack: &[u8], span: Span) -> Option<Span> {
        let b = *haystack.get(span.start)?;
        if self.0[usize::from(b)] {
            Some(Span { start: span.start, end: span.start + 1 })
        } else {
            None
        }
    }

    fn memory_usage(&self) -> usize {
        0
    }

    fn is_fast(&self) -> bool {
        false
    }
}

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/regex-automata-0.4.9/src/util/prefilter/byteset.rs
wasmtime-28.0.0 ./ext/cargo-vendor/regex-automata-0.4.9/src/util/prefilter/byteset.rs
wasmtime-27.0.0 ./ext/cargo-vendor/regex-automata-0.4.9/src/util/prefilter/byteset.rs
wasmtime-26.0.0 ./ext/cargo-vendor/regex-automata-0.4.8/src/util/prefilter/byteset.rs
wasmtime-25.0.2 ./ext/cargo-vendor/regex-automata-0.4.7/src/util/prefilter/byteset.rs
wasmtime-25.0.1 ./ext/cargo-vendor/regex-automata-0.4.7/src/util/prefilter/byteset.rs
wasmtime-25.0.0 ./ext/cargo-vendor/regex-automata-0.4.7/src/util/prefilter/byteset.rs
wasmtime-24.0.0 ./ext/cargo-vendor/regex-automata-0.4.7/src/util/prefilter/byteset.rs
wasmtime-23.0.2 ./ext/cargo-vendor/regex-automata-0.4.3/src/util/prefilter/byteset.rs
wasmtime-22.0.0 ./ext/cargo-vendor/regex-automata-0.4.3/src/util/prefilter/byteset.rs
wasmtime-21.0.1 ./ext/cargo-vendor/regex-automata-0.4.3/src/util/prefilter/byteset.rs
wasmtime-20.0.2 ./ext/cargo-vendor/regex-automata-0.4.3/src/util/prefilter/byteset.rs
wasmtime-20.0.0 ./ext/cargo-vendor/regex-automata-0.4.3/src/util/prefilter/byteset.rs
wasmtime-18.0.3 ./ext/cargo-vendor/regex-automata-0.4.3/src/util/prefilter/byteset.rs
wasmtime-17.0.1 ./ext/cargo-vendor/regex-automata-0.4.3/src/util/prefilter/byteset.rs
wasmtime-17.0.0 ./ext/cargo-vendor/regex-automata-0.4.3/src/util/prefilter/byteset.rs
wasmtime-16.0.0 ./ext/cargo-vendor/regex-automata-0.4.3/src/util/prefilter/byteset.rs
wasmtime-15.0.1 ./ext/cargo-vendor/regex-automata-0.4.3/src/util/prefilter/byteset.rs
wasmtime-15.0.0 ./ext/cargo-vendor/regex-automata-0.4.3/src/util/prefilter/byteset.rs
wasmtime-14.0.4 ./ext/cargo-vendor/regex-automata-0.4.3/src/util/prefilter/byteset.rs