From e63471f7a33133861b5c703ee1e3ec599bff9c16 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 28 Aug 2023 20:59:37 +0000 Subject: [PATCH] Drop `memchr` dependency While `memchr` has served us well, it finally bumped its MSRV substantially such that its no longer really practical in a particularly MSRV-constrained environment (e.g. when building on machines with validated toolchains or Debian stable). Luckily, its barely used, and not really worth retaining. A trivial scan should be something LLVM can optimize at least somewhat reasonably. --- Cargo.toml | 1 - src/io/buffered.rs | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 68e2fef..116541e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,6 @@ repository = "https://github.com/bbqsrc/core2" categories = ["no-std"] [dependencies] -memchr = { version = "2", default-features = false } [features] default = ["std"] diff --git a/src/io/buffered.rs b/src/io/buffered.rs index 4a03c93..f5cbca7 100644 --- a/src/io/buffered.rs +++ b/src/io/buffered.rs @@ -808,7 +808,7 @@ impl<'a, W: Write, const S: usize> Write for LineWriterShim<'a, W, S> { /// writer, it will also flush the existing buffer if it ends with a /// newline, even if the incoming data does not contain any newlines. fn write(&mut self, buf: &[u8]) -> Result { - let newline_idx = match memchr::memrchr(b'\n', buf) { + let newline_idx = match buf.iter().rev().position(|b| *b == b'\n') { // If there are no new newlines (that is, if this write is less than // one line), just do a regular buffered write (which may flush if // we exceed the inner buffer's size) @@ -866,7 +866,7 @@ impl<'a, W: Write, const S: usize> Write for LineWriterShim<'a, W, S> { } else { let scan_area = &buf[flushed..]; let scan_area = &scan_area[..self.buffer.capacity()]; - match memchr::memrchr(b'\n', scan_area) { + match scan_area.iter().rev().position(|b| *b == b'\n') { Some(newline_idx) => &scan_area[..newline_idx + 1], None => scan_area, } @@ -889,7 +889,7 @@ impl<'a, W: Write, const S: usize> Write for LineWriterShim<'a, W, S> { /// writer, it will also flush the existing buffer if it contains any /// newlines, even if the incoming data does not contain any newlines. fn write_all(&mut self, buf: &[u8]) -> Result<()> { - match memchr::memrchr(b'\n', buf) { + match buf.iter().rev().position(|b| *b == b'\n') { // If there are no new newlines (that is, if this write is less than // one line), just do a regular buffered write (which may flush if // we exceed the inner buffer's size)