Skip to content

Commit

Permalink
feat: Move memchr behind an optional feature
Browse files Browse the repository at this point in the history
Closes #76

Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull authored Nov 15, 2023
1 parent 7dbe294 commit e94a46b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
uses: taiki-e/install-action@cargo-hack
- run: cargo build --all --all-features --all-targets
- run: cargo hack build --feature-powerset --no-dev-deps
- run: cargo hack build --feature-powerset --no-dev-deps --target thumbv7m-none-eabi --skip std,default
- run: cargo hack build --feature-powerset --no-dev-deps --target thumbv7m-none-eabi --skip std,default,memchr
- run: cargo test
- run: cargo test --no-default-features
- run: cargo test --no-default-features --features alloc
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exclude = ["/.*"]

[features]
default = ["race", "std"]
std = ["alloc", "fastrand/std", "futures-io", "parking", "memchr"]
std = ["alloc", "fastrand/std", "futures-io", "parking"]
alloc = []
race = ["fastrand"]

Expand Down
11 changes: 10 additions & 1 deletion src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,7 @@ fn read_until_internal<R: AsyncBufReadExt + ?Sized>(
let (done, used) = {
let available = ready!(reader.as_mut().poll_fill_buf(cx))?;

if let Some(i) = memchr::memchr(byte, available) {
if let Some(i) = memchr(byte, available) {
buf.extend_from_slice(&available[..=i]);
(true, i + 1)
} else {
Expand Down Expand Up @@ -3091,3 +3091,12 @@ impl<T: AsyncWrite + Unpin> AsyncWrite for WriteHalf<T> {
Pin::new(&mut *inner).poll_close(cx)
}
}

#[cfg(feature = "memchr")]
use memchr::memchr;

/// Unoptimized memchr fallback.
#[cfg(not(feature = "memchr"))]
fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> {
haystack.iter().position(|&b| b == needle)
}

0 comments on commit e94a46b

Please sign in to comment.