Skip to content

Commit e94a46b

Browse files
authored
feat: Move memchr behind an optional feature
Closes #76 Signed-off-by: John Nunley <[email protected]>
1 parent 7dbe294 commit e94a46b

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
uses: taiki-e/install-action@cargo-hack
4343
- run: cargo build --all --all-features --all-targets
4444
- run: cargo hack build --feature-powerset --no-dev-deps
45-
- run: cargo hack build --feature-powerset --no-dev-deps --target thumbv7m-none-eabi --skip std,default
45+
- run: cargo hack build --feature-powerset --no-dev-deps --target thumbv7m-none-eabi --skip std,default,memchr
4646
- run: cargo test
4747
- run: cargo test --no-default-features
4848
- run: cargo test --no-default-features --features alloc

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ exclude = ["/.*"]
2121

2222
[features]
2323
default = ["race", "std"]
24-
std = ["alloc", "fastrand/std", "futures-io", "parking", "memchr"]
24+
std = ["alloc", "fastrand/std", "futures-io", "parking"]
2525
alloc = []
2626
race = ["fastrand"]
2727

src/io.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ fn read_until_internal<R: AsyncBufReadExt + ?Sized>(
18111811
let (done, used) = {
18121812
let available = ready!(reader.as_mut().poll_fill_buf(cx))?;
18131813

1814-
if let Some(i) = memchr::memchr(byte, available) {
1814+
if let Some(i) = memchr(byte, available) {
18151815
buf.extend_from_slice(&available[..=i]);
18161816
(true, i + 1)
18171817
} else {
@@ -3091,3 +3091,12 @@ impl<T: AsyncWrite + Unpin> AsyncWrite for WriteHalf<T> {
30913091
Pin::new(&mut *inner).poll_close(cx)
30923092
}
30933093
}
3094+
3095+
#[cfg(feature = "memchr")]
3096+
use memchr::memchr;
3097+
3098+
/// Unoptimized memchr fallback.
3099+
#[cfg(not(feature = "memchr"))]
3100+
fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> {
3101+
haystack.iter().position(|&b| b == needle)
3102+
}

0 commit comments

Comments
 (0)