Skip to content

Commit

Permalink
perf(primitives): optimize AccountInfo.is_empty() (#922)
Browse files Browse the repository at this point in the history
* perf(primitives): optimize AccountInfo.is_empty()

This is a small optimization for AccountInfo.is_empty() with
regards to the short-circuiting of bool operators in Rust.

* fix(primitives): incorrect use of the cfg attribute
  • Loading branch information
IaroslavMazur authored Dec 25, 2023
1 parent 67331de commit 42caf55
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ impl CfgEnv {
false
}

#[cfg(feaure = "optional_beneficiary_reward")]
#[cfg(feature = "optional_beneficiary_reward")]
pub fn is_beneficiary_reward_disabled(&self) -> bool {
self.disable_beneficiary_reward
}

#[cfg(not(feaure = "optional_beneficiary_reward"))]
#[cfg(not(feature = "optional_beneficiary_reward"))]
pub fn is_beneficiary_reward_disabled(&self) -> bool {
false
}
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl AccountInfo {
/// - nonce is zero
pub fn is_empty(&self) -> bool {
let code_empty = self.is_empty_code_hash() || self.code_hash == B256::ZERO;
self.balance == U256::ZERO && self.nonce == 0 && code_empty
code_empty && self.balance == U256::ZERO && self.nonce == 0
}

/// Returns `true` if the account is not empty.
Expand Down

0 comments on commit 42caf55

Please sign in to comment.