refactor: use is_none_or instead of map_or (#13035)

This commit is contained in:
Hoa Nguyen
2024-11-30 18:09:49 +07:00
committed by GitHub
parent 5d71150355
commit 0ff2827a79
8 changed files with 9 additions and 9 deletions

View File

@ -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(),

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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 => {

View File

@ -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)
}
}

View File

@ -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);
}

View File

@ -76,7 +76,7 @@ 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.
@ -84,7 +84,7 @@ impl CursorSubNode {
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.