mirror of
https://github.com/openai/codex.git
synced 2026-10-19 17:28:46 +00:00
Use mem::take to drain unified exec output buffers (#39515)
## What changed Replace the custom `HeadTailBuffer::drain` helper with `std::mem::take` at the output collection call site. This moves the buffered output out while resetting the shared buffer to its default empty state. GitOrigin-RevId: 7a93d1312f2cea0d7913a5264eeb01726b45e0ea
This commit is contained in:
committed by
copyberry
parent
db675cc005
commit
18937b2265
@@ -93,16 +93,6 @@ impl<const MAX_BYTES: usize> HeadTailBuffer<MAX_BYTES> {
|
||||
out
|
||||
}
|
||||
|
||||
/// Drain the retained output and omission metadata, resetting this buffer's
|
||||
/// contents while preserving its configured capacity.
|
||||
pub(crate) fn drain(&mut self) -> Self {
|
||||
Self {
|
||||
head: std::mem::take(&mut self.head),
|
||||
tail: std::mem::take(&mut self.tail),
|
||||
omitted_bytes: std::mem::take(&mut self.omitted_bytes),
|
||||
}
|
||||
}
|
||||
|
||||
/// Append a later buffer with the same budget. This preserves the summary
|
||||
/// of the original concatenated output, including its omission count.
|
||||
pub(crate) fn push_buffer(&mut self, mut buffer: Self) {
|
||||
|
||||
@@ -42,24 +42,6 @@ fn head_budget_zero_keeps_only_last_byte_in_tail() {
|
||||
assert_eq!(buf.to_bytes(), b"c".to_vec());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn draining_resets_state_and_push_buffer_preserves_omissions() {
|
||||
let mut buf = HeadTailBuffer::<10>::default();
|
||||
buf.push_chunk(b"0123456789".to_vec());
|
||||
buf.push_chunk(b"ab".to_vec());
|
||||
|
||||
let drained = buf.drain();
|
||||
let mut collected = HeadTailBuffer::<10>::default();
|
||||
collected.push_buffer(drained);
|
||||
|
||||
assert_eq!(buf.retained_bytes(), 0);
|
||||
assert_eq!(buf.omitted_bytes(), 0);
|
||||
assert_eq!(buf.to_bytes(), b"".to_vec());
|
||||
assert_eq!(collected.to_bytes(), b"01234789ab".to_vec());
|
||||
assert_eq!(collected.omitted_bytes(), 2);
|
||||
assert_eq!(collected.total_bytes(), 12);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chunk_larger_than_tail_budget_keeps_only_tail_end() {
|
||||
let mut buf = HeadTailBuffer::<10>::default();
|
||||
|
||||
@@ -1344,7 +1344,7 @@ impl UnifiedExecProcessManager {
|
||||
let mut wait_for_output = None;
|
||||
{
|
||||
let mut guard = output_buffer.lock().await;
|
||||
drained_output = guard.drain();
|
||||
drained_output = std::mem::take(&mut *guard);
|
||||
has_drained_output =
|
||||
drained_output.retained_bytes() > 0 || drained_output.omitted_bytes() > 0;
|
||||
if !has_drained_output {
|
||||
|
||||
Reference in New Issue
Block a user