Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

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

Brent Traut8c3612fb638d
diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock
index a26f2fd61e..10a8c44279 100644
--- a/codex-rs/Cargo.lock
+++ b/codex-rs/Cargo.lock
@@ -4432,6 +4432,7 @@ dependencies = [
"codex-utils-absolute-path",
"codex-utils-path",
"codex-utils-process",
+ "memchr",
"pretty_assertions",
"regex",
"serde",
diff --git a/codex-rs/rollout/Cargo.toml b/codex-rs/rollout/Cargo.toml
index 8981dd9662..fb2b5b39e4 100644
--- a/codex-rs/rollout/Cargo.toml
+++ b/codex-rs/rollout/Cargo.toml
@@ -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 }
diff --git a/codex-rs/rollout/src/reverse_jsonl_scanner.rs b/codex-rs/rollout/src/reverse_jsonl_scanner.rs
index 9e0a836bee..ed0daed295 100644
--- a/codex-rs/rollout/src/reverse_jsonl_scanner.rs
+++ b/codex-rs/rollout/src/reverse_jsonl_scanner.rs
@@ -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| {