-
Notifications
You must be signed in to change notification settings - Fork 750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid useless memory copies in IPC reader. #2510
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,14 +53,11 @@ fn read_buffer( | |
) -> Result<Buffer> { | ||
let start_offset = buf.offset() as usize; | ||
let end_offset = start_offset + buf.length() as usize; | ||
let buf_data = &a_data[start_offset..end_offset]; | ||
let buf_data = Buffer::from(&a_data[start_offset..end_offset]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we cannot slice on Buffer with length, we cannot implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the calculation above, I think we don't need to truncate the length, as end_offset is the end of the buffer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aah yes, brain fart on my part. R.e. making a_data a Buffer, we could always pass the length separately... |
||
// corner case: empty buffer | ||
if buf_data.is_empty() { | ||
return Ok(Buffer::from(buf_data)); | ||
} | ||
match compression_codec { | ||
Some(decompressor) => decompressor.decompress_to_buffer(buf_data), | ||
None => Ok(Buffer::from(buf_data)), | ||
match (buf_data.is_empty(), compression_codec) { | ||
(true, _) | (_, None) => Ok(buf_data), | ||
(false, Some(decompressor)) => decompressor.decompress_to_buffer(&buf_data), | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️