Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move memchr behind an optional feature #77

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}