Use memrchr to find newlines in reverse JSONL scans (#49444)

Replace the byte-by-byte reverse newline search with `memchr::memrchr` and add `memchr` as a dependency of `codex-rollout`.

GitOrigin-RevId: b07e42e15efb0d63d7b00ee9a2ee29c446f4cf59
This commit is contained in:
Brent Traut
2026-09-30 02:19:47 +00:00
committed by copyberry
parent 6ba4bf9e64
commit 8c3612fb63
3 changed files with 3 additions and 1 deletions
+1
View File
@@ -4432,6 +4432,7 @@ dependencies = [
"codex-utils-absolute-path",
"codex-utils-path",
"codex-utils-process",
"memchr",
"pretty_assertions",
"regex",
"serde",
+1
View File
@@ -25,6 +25,7 @@ codex-protocol = { workspace = true }
codex-state = { workspace = true }
codex-utils-absolute-path = { workspace = true }
codex-utils-path = { workspace = true }
memchr = { workspace = true }
regex = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
@@ -95,7 +95,7 @@ where
}
let chunk = &self.chunk[..self.chunk_position];
if let Some(newline_position) = chunk.iter().rposition(|byte| *byte == b'\n') {
if let Some(newline_position) = memchr::memrchr(b'\n', chunk) {
let fragment = &chunk[newline_position + 1..];
if !self.discarding_oversized_record {
if self.max_record_bytes.is_some_and(|max_record_bytes| {