refactor: improve buffer handling logic and comments

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-18 20:54:42 -03:00
parent cec6081218
commit ff5d233509

View File

@@ -58,18 +58,23 @@ impl MetaPlugin for BinaryMetaPlugin {
return; return;
} }
// Add data to buffer // Calculate how much data we can still accept
let remaining_capacity = self.max_buffer_size.saturating_sub(self.buffer.len()); let remaining_capacity = self.max_buffer_size.saturating_sub(self.buffer.len());
if remaining_capacity > 0 { if remaining_capacity == 0 {
let bytes_to_copy = std::cmp::min(data.len(), remaining_capacity); return;
self.buffer.extend_from_slice(&data[..bytes_to_copy]); }
// If we've reached the buffer limit, save the metadata immediately // Determine how much data to copy
let bytes_to_take = std::cmp::min(data.len(), remaining_capacity);
// Add data to our buffer
self.buffer.extend_from_slice(&data[..bytes_to_take]);
// If we've reached our buffer limit, save the metadata immediately
if self.buffer.len() >= self.max_buffer_size { if self.buffer.len() >= self.max_buffer_size {
let _ = self.save_metadata(conn); let _ = self.save_metadata(conn);
} }
} }
}
fn meta_name(&mut self) -> String { fn meta_name(&mut self) -> String {
self.meta_name.clone() self.meta_name.clone()