-
Notifications
You must be signed in to change notification settings - Fork 258
use copy_from_slice over write_all #4437
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
Conversation
WalkthroughThis pull request streamlines how data is written into byte slices in two modules. In the consensus module, the function setting the header’s nonce now directly copies the little-endian bytes for both the nonce and additional data into the header. In the stratum module, updating the minting blob in the job response now directly copies the worker ID buffer into a slice, replacing the previous mutable borrow and write operations. No functional or public interface changes are made. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Function Caller
participant SetHeader as set_header_nonce
participant Header as Header Array
Caller->>SetHeader: Call set_header_nonce(nonce, extra)
SetHeader->>Header: Copy nonce bytes via copy_from_slice
SetHeader->>Header: Copy extra data via copy_from_slice
SetHeader-->>Caller: Return updated header
sequenceDiagram
participant Caller as Function Caller
participant FromMethod as StratumJobResponse::from
participant MintingBlob as Minting Blob
Caller->>FromMethod: Call from(worker_id)
FromMethod->>MintingBlob: Copy worker_id.buff using copy_from_slice
FromMethod-->>Caller: Return StratumJobResponse instance
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
consensus/src/lib.rs (1)
4-11
: Consider updating import statementSince the refactoring has removed the usage of
WriteBytesExt
methods, you could also remove the related import:-use byteorder::{LittleEndian, WriteBytesExt}; +use byteorder::LittleEndian;The
LittleEndian
type is still used elsewhere in the file (e.g., line 114), so it should be kept.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
consensus/src/lib.rs
(1 hunks)stratum/src/rpc.rs
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Generate code coverage report
🔇 Additional comments (2)
stratum/src/rpc.rs (1)
268-268
: Cleaner implementation using copy_from_sliceThe change from using
borrow_mut().write_all(&worker_id.buff)
tocopy_from_slice(&worker_id.buff)
is a good improvement. This simplifies the code by eliminating the need for mutable borrowing and the associated Write trait operations, making it more idiomatic Rust.The operation is more direct and likely more efficient for this simple buffer copying scenario, as it avoids the additional abstraction layers and potential error handling of the Write trait.
consensus/src/lib.rs (1)
51-52
: Code simplification with direct slice operationsThis change replaces the previous implementation that used
WriteBytesExt
methods (write_u32
andwrite_all
) with direct slice operations viacopy_from_slice
. This is a good refactoring because:
- It eliminates intermediate mutable references and method calls
- Makes the code more concise and easier to understand
- Potentially improves performance by using a more direct approach to memory copying
The implementation correctly handles both the extra bytes and the little-endian conversion of the nonce value, maintaining the original functionality.
Benchmark for 8353f6fClick to view benchmark
|
Benchmark for 2c7a21dClick to view benchmark
|
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.
LGTM
* use copy_from_slice over write_all * fix cargo check
* use copy_from_slice over write_all * fix cargo check
* use rust 1.82.0 and add storage2/executor2 * Revert "select default vm executor to fix tests (#4435)" * Revert "split transactions to different vm (#4432)" * fix building error * init storage2 when booting * add executor2 * use copy_from_slice over write_all (#4437) * use copy_from_slice over write_all * fix cargo check * fix rust upate warning (#4446) * fix compiler warning * fix commit * update clippy * update rust * fix rust update warning * remove unused manifest keys * remove unncessary default-features * in flavor of config.toml --------- Co-authored-by: nk_ysg <[email protected]>
Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Other information
Summary by CodeRabbit