Skip to content

Commit

Permalink
refactor: use is_none_or instead of map_or (#13035)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 authored Nov 30, 2024
1 parent 5d71150 commit 0ff2827
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/net/eth-wire/src/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub fn shared_capability_offsets(
// highest wins, others are ignored
if shared_capabilities
.get(&peer_capability.name)
.map_or(true, |v| peer_capability.version > v.version)
.is_none_or(|v| peer_capability.version > v.version)
{
shared_capabilities.insert(
peer_capability.name.clone(),
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives-traits/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Account {
pub fn is_empty(&self) -> bool {
self.nonce == 0 &&
self.balance.is_zero() &&
self.bytecode_hash.map_or(true, |hash| hash == KECCAK_EMPTY)
self.bytecode_hash.is_none_or(|hash| hash == KECCAK_EMPTY)
}

/// Returns an account bytecode's hash.
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<T> BlockBatchRecord<T> {

/// Returns the [`BundleRetention`] for the given block based on the configured prune modes.
pub fn bundle_retention(&self, block_number: BlockNumber) -> BundleRetention {
if self.tip.map_or(true, |tip| {
if self.tip.is_none_or(|tip| {
!self
.prune_modes
.account_history
Expand Down
2 changes: 1 addition & 1 deletion crates/static-file/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl StaticFileTargets {
]
.iter()
.all(|(target_block_range, highest_static_fileted_block)| {
target_block_range.map_or(true, |target_block_range| {
target_block_range.is_none_or(|target_block_range| {
*target_block_range.start() ==
highest_static_fileted_block.map_or(0, |highest_static_fileted_block| {
highest_static_fileted_block + 1
Expand Down
2 changes: 1 addition & 1 deletion crates/tracing/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl LogFormat {
.unwrap_or_else(|_|
// If `RUST_LOG_TARGET` is not set, show target in logs only if the max enabled
// level is higher than INFO (DEBUG, TRACE)
filter.max_level_hint().map_or(true, |max_level| max_level > tracing::Level::INFO));
filter.max_level_hint().is_none_or(|max_level| max_level > tracing::Level::INFO));

match self {
Self::Json => {
Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/maintain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl FinalizedBlockTracker {
let finalized = finalized_block?;
self.last_finalized_block
.replace(finalized)
.map_or(true, |last| last < finalized)
.is_none_or(|last| last < finalized)
.then_some(finalized)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/pool/best.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<T: TransactionOrdering> Iterator for BestTransactionsWithFees<T> {
if best.transaction.max_fee_per_gas() >= self.base_fee as u128 &&
best.transaction
.max_fee_per_blob_gas()
.map_or(true, |fee| fee >= self.base_fee_per_blob_gas as u128)
.is_none_or(|fee| fee >= self.base_fee_per_blob_gas as u128)
{
return Some(best);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/trie/trie/src/trie_cursor/subnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ impl CursorSubNode {
pub fn state_flag(&self) -> bool {
self.node
.as_ref()
.map_or(true, |node| self.nibble < 0 || node.state_mask.is_bit_set(self.nibble as u8))
.is_none_or(|node| self.nibble < 0 || node.state_mask.is_bit_set(self.nibble as u8))
}

/// Returns `true` if the tree flag is set for the current nibble.
#[inline]
pub fn tree_flag(&self) -> bool {
self.node
.as_ref()
.map_or(true, |node| self.nibble < 0 || node.tree_mask.is_bit_set(self.nibble as u8))
.is_none_or(|node| self.nibble < 0 || node.tree_mask.is_bit_set(self.nibble as u8))
}

/// Returns `true` if the current nibble has a root hash.
Expand Down

0 comments on commit 0ff2827

Please sign in to comment.