refactor(starknet): remove redundant clone calls in dispatcher#9692
refactor(starknet): remove redundant clone calls in dispatcher#9692radik878 wants to merge 2 commits intostarkware-libs:mainfrom
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 1 file and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on radik878).
orizi
left a comment
There was a problem hiding this comment.
@orizi made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on radik878).
crates/cairo-lang-starknet/src/plugin/dispatcher.rs line 435 at r1 (raw file):
Result::Ok(\n $deserialization_code$\n )" ) },
this actually has possibly more clones than before still.
Suggestion:
serialization_code: Vec<RewriteNode<'db>>,
ret_decode: String,
unwrap: bool,
) -> RewriteNode<'db> {
let ret_decode_is_empty = ret_decode.is_empty();
let deserialization_code = if ret_decode_is_empty {
RewriteNode::text("()")
} else {
RewriteNode::Text(if unwrap {
ret_decode
} else {
ret_decode.split('\n').map(|x| format!(" {x}")).join("\n")
})
};
let return_code = RewriteNode::interpolate_patched(
&if unwrap {
format!(
"let mut {RET_DATA} = starknet::SyscallResultTrait::unwrap_syscall({RET_DATA});
$deserialization_code$"
)
} else if ret_decode_is_empty {
format!(
"let mut {RET_DATA} = {RET_DATA}?;
Result::Ok($deserialization_code$)"
)
} else {
format!(
"let mut {RET_DATA} = {RET_DATA}?;
Result::Ok(\n $deserialization_code$\n )"
)
},
|
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed all commit messages and made 1 comment.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on radik878).
crates/cairo-lang-starknet/src/plugin/dispatcher.rs line 435 at r1 (raw file):
Previously, orizi wrote…
this actually has possibly more clones than before still.
please answer at https://reviewable.io/reviews/starkware-libs/cairo/9692#-
it did not compile because you didn't change the callsite.
Summary
Changed
ret_decodeparameter fromStringto&strand updated call sites to pass references instead of cloned values, eliminating 7 unnecessary allocations per interface function processed.Type of change
Why is this change needed?
The dispatcher plugin was making unnecessary
.clone()calls when passingret_decode(String),serialization_code(Vec), andentry_point_selector(RewriteNode) to thedeclaration_method_implfunction. These values were either moved or not modified after being passed, making the clones redundant.