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,16 +58,21 @@ impl MetaPlugin for BinaryMetaPlugin {
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());
if remaining_capacity > 0 {
let bytes_to_copy = std::cmp::min(data.len(), remaining_capacity);
self.buffer.extend_from_slice(&data[..bytes_to_copy]);
if remaining_capacity == 0 {
return;
}
// If we've reached the buffer limit, save the metadata immediately
if self.buffer.len() >= self.max_buffer_size {
let _ = self.save_metadata(conn);
}
// 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 {
let _ = self.save_metadata(conn);
}
}