feat: Move memchr behind an optional feature
Closes #76 Signed-off-by: John Nunley <dev@notgull.net>
This commit is contained in:
parent
7dbe2945e1
commit
e94a46be67
|
@ -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
|
||||
|
|
|
@ -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"]
|
||||
|
||||
|
|
11
src/io.rs
11
src/io.rs
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue