Avoid cloning byte arrays in public methods#574
Conversation
|
Welcome @jkosh44! It looks like this is your first PR to tikv/raft-rs 🎉 |
|
There isn't an open issue that I could find about this, but it's a simple enough change that it seemed easier to discuss over the implementation rather than an issue. |
|
Just bumping this in case it fell through the cracks. @BusyJay any interest in this change? |
|
Can you rebase master? |
When the `protobuf-codec` feature is enabled, `bytes::Bytes` is used for byte arrays in protobuf objects instead of `Vec<u8>`. Previously, all of the public methods in `RawNode` accepted only `Vec<u8>`. If the caller had an instance of `bytes::Bytes`, they'd by forced to clone it, pass it to the method, only for the method to convert it back into `bytes::Bytes`. This commit updates the public methods of `RawNode` so that they accept any type that can be converted into `bytes::Bytes` when `protobuf-codec` is enabled, and any type that can be converted into `Vec<u8>` when it's not enabled. This will allow callers to pass in their own `bytes::Bytes` instead of cloning them. This change is backwards compatible because `Vec<u8>` implements both `Into<Vec<u8>>` and `Into<bytes::Bytes>`. Signed-off-by: Joseph Koshakow <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can customize the high-level summary generated by CodeRabbit.Configure the |
Done. |
|
Thanks! |
When the
protobuf-codecfeature is enabled,bytes::Bytesis used for byte arrays in protobuf objects instead ofVec<u8>. Previously, all of the public methods inRawNodeaccepted onlyVec<u8>. If the caller had an instance ofbytes::Bytes, they'd by forced to clone it, pass it to the method, only for the method to convert it back intobytes::Bytes.This commit updates the public methods of
RawNodeso that they accept any type that can be converted intobytes::Byteswhenprotobuf-codecis enabled, and any type that can be converted intoVec<u8>when it's not enabled. This will allow callers to pass in their ownbytes::Bytesinstead of cloning them.This change is backwards compatible because
Vec<u8>implements bothInto<Vec<u8>>andInto<bytes::Bytes>.Summary by CodeRabbit
Release Notes
propose,propose_conf_change, andread_index) now accept more flexible input types for context and data parameters, enabling cleaner API usage.