mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Simplify eviction in the log ring buffer (#63235)
## What changed Use `VecDeque::retain_back` to keep only as many existing bytes as will fit alongside the incoming chunk. The buffer still keeps the most recent bytes up to its configured capacity. GitOrigin-RevId: 45fd8fa09e47647ad09b26327e2753bc4573b6c6
This commit is contained in:
committed by
copyberry
parent
1b0b42bfca
commit
c9325ea78c
@@ -362,10 +362,6 @@ impl RingBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.buf.len()
|
||||
}
|
||||
|
||||
fn push_bytes(&mut self, data: &[u8]) {
|
||||
if data.is_empty() {
|
||||
return;
|
||||
@@ -379,15 +375,7 @@ impl RingBuffer {
|
||||
return;
|
||||
}
|
||||
|
||||
// Evict from the front if we would exceed capacity.
|
||||
let needed = self.len() + data.len();
|
||||
if needed > self.max {
|
||||
let to_drop = needed - self.max;
|
||||
for _ in 0..to_drop {
|
||||
let _ = self.buf.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
self.buf.retain_back(self.max - data.len());
|
||||
self.buf.extend(data.iter().copied());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user