Skip to content

Commit

Permalink
move to jetscii
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Jan 17, 2022
1 parent 54123e7 commit d759695
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ glob = "0.3.0"
libtest-mimic = "0.3.0"

[features]
# By default this crate depends on the memchr library for best performance.
# By default this crate depends on the jetscii library for best performance.
# Disabling this feature will leave you with 100% safe Rust and no dependencies.
# This may come in handy if you encounter packaging/build problems.
default = ["memchr"]
default = ["jetscii"]

# If this feature is enabled, html5gum will expose private APIs and start
# printing debug information to stdout.
integration-tests = []

[dependencies]
memchr = { version = "2.4.1", optional = true }
jetscii = { version = "0.5.1", optional = true }

[[bench]]
name = "data_state"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ This allows you to:
## Other features

* No unsafe Rust
* Only dependency is `memchr`, and can be disabled via crate features (see `Cargo.toml`)
* Only dependency is `jetscii`, and can be disabled via crate features (see `Cargo.toml`)

## Alternative HTML parsers

Expand Down
23 changes: 6 additions & 17 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pub trait Reader {
///
/// The default implementation simply reads one character and calls `read_cb` with that
/// character, ignoring the needle entirely. It is recommended to manually implement
/// `read_until` if there is any sort of in-memory buffer where `memchr` can be run on.
/// `read_until` if there is any sort of in-memory buffer where some sort of efficient string
/// search (see `memchr` or `jetscii` crate) can be run on.
///
/// The return value is usually borrowed from underlying buffers. If that's not possible, a
/// small buffer is provided as `char_buf` to put a single character into.
Expand Down Expand Up @@ -384,20 +385,8 @@ impl<'a> Readable<'a> for File {

#[inline]
fn fast_find(needle: &[u8], haystack: &[u8]) -> Option<usize> {
#[cfg(feature = "memchr")]
if needle.iter().all(u8::is_ascii) {
if needle.len() == 3 {
return memchr::memchr3(needle[0], needle[1], needle[2], haystack);
} else if needle.len() == 2 {
return memchr::memchr2(needle[0], needle[1], haystack);
} else if needle.len() == 1 {
return memchr::memchr(needle[0], haystack);
}
}

let (i, _) = haystack
.iter()
.enumerate()
.find(|(_, &b)| needle.contains(&b))?;
Some(i)
debug_assert!(needle.len() <= 16);
let mut needle_arr = [0; 16];
needle_arr[..needle.len()].copy_from_slice(needle);
jetscii::Bytes::new(needle_arr, needle.len() as i32, |b| needle.contains(&b)).find(haystack)
}

0 comments on commit d759695

Please sign in to comment.