feat: Move memchr behind an optional feature

Closes #76

Signed-off-by: John Nunley <dev@notgull.net>
This commit is contained in:
John Nunley 2023-11-14 20:28:35 -08:00 committed by GitHub
parent 7dbe2945e1
commit e94a46be67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View File

@ -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

View File

@ -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"]

View File

@ -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)
}