Skip to content

Commit

Permalink
clippy: unnecessary_map_or
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed Jan 10, 2025
1 parent 67d5858 commit 3cb2ba7
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 21 deletions.
4 changes: 1 addition & 3 deletions accounts-db/src/account_locks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ impl AccountLocks {

#[cfg_attr(feature = "dev-context-only-utils", qualifiers(pub))]
fn is_locked_readonly(&self, key: &Pubkey) -> bool {
self.readonly_locks
.get(key)
.map_or(false, |count| *count > 0)
self.readonly_locks.get(key).is_some_and(|count| *count > 0)
}

#[cfg_attr(feature = "dev-context-only-utils", qualifiers(pub))]
Expand Down
2 changes: 1 addition & 1 deletion bench-tps/src/log_transaction_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ impl TransactionLogWriter {
.latest()
.expect("valid timestamp")
}),
successful: meta.as_ref().map_or(false, |m| m.status.is_ok()),
successful: meta.as_ref().is_some_and(|m| m.status.is_ok()),
error: meta
.as_ref()
.and_then(|m| m.err.as_ref().map(|x| x.to_string())),
Expand Down
2 changes: 1 addition & 1 deletion core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,7 @@ impl ReplayStage {
// The following differs from rooted_slots by including the parent slot of the oldest parent bank.
let rooted_slots_with_parents = bank_notification_sender
.as_ref()
.map_or(false, |sender| sender.should_send_parents)
.is_some_and(|sender| sender.should_send_parents)
.then(|| {
let mut new_chain = rooted_slots.clone();
new_chain.push(oldest_parent.unwrap_or_else(|| bank.parent_slot()));
Expand Down
4 changes: 1 addition & 3 deletions core/src/warm_quic_cache_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ impl WarmQuicCacheService {
.unwrap()
.leader_after_n_slots((CACHE_OFFSET_SLOT + slot_jitter) as u64);
if let Some(leader_pubkey) = leader_pubkey {
if maybe_last_leader
.map_or(true, |last_leader| last_leader != leader_pubkey)
{
if maybe_last_leader != Some(leader_pubkey) {
maybe_last_leader = Some(leader_pubkey);
// Warm cache for regular transactions
Self::warmup_connection(
Expand Down
9 changes: 4 additions & 5 deletions poh/src/poh_recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,14 @@ impl PohRecorder {

pub fn would_be_leader(&self, within_next_n_ticks: u64) -> bool {
self.has_bank()
|| self.leader_first_tick_height_including_grace_ticks.map_or(
false,
|leader_first_tick_height_including_grace_ticks| {
|| self
.leader_first_tick_height_including_grace_ticks
.is_some_and(|leader_first_tick_height_including_grace_ticks| {
let ideal_leader_tick_height = leader_first_tick_height_including_grace_ticks
.saturating_sub(self.grace_ticks);
self.tick_height + within_next_n_ticks >= ideal_leader_tick_height
&& self.tick_height <= self.leader_last_tick_height
},
)
})
}

// Return the slot for a given tick height
Expand Down
2 changes: 1 addition & 1 deletion programs/vote/src/vote_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ fn check_slots_are_valid(
// where `s` >= `last_voted_slot`
if vote_state
.last_voted_slot()
.map_or(false, |last_voted_slot| vote_slots[i] <= last_voted_slot)
.is_some_and(|last_voted_slot| vote_slots[i] <= last_voted_slot)
{
i = i
.checked_add(1)
Expand Down
4 changes: 1 addition & 3 deletions runtime/src/snapshot_archive_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ pub trait SnapshotArchiveInfoGetter {
self.snapshot_archive_info()
.path
.parent()
.map_or(false, |p| {
p.ends_with(snapshot_utils::SNAPSHOT_ARCHIVE_DOWNLOAD_DIR)
})
.is_some_and(|p| p.ends_with(snapshot_utils::SNAPSHOT_ARCHIVE_DOWNLOAD_DIR))
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl FromStr for SnapshotVersion {
// Remove leading 'v' or 'V' from slice
let version_string = if version_string
.get(..1)
.map_or(false, |s| s.eq_ignore_ascii_case("v"))
.is_some_and(|s| s.eq_ignore_ascii_case("v"))
{
&version_string[1..]
} else {
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/vote/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ impl VoteState {
// Ignore votes for slots earlier than we already have votes for
if self
.last_voted_slot()
.map_or(false, |last_voted_slot| next_vote_slot <= last_voted_slot)
.is_some_and(|last_voted_slot| next_vote_slot <= last_voted_slot)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion validator/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn get_rpc_peers(
cluster_entrypoint
.gossip()
.and_then(|addr| cluster_info.lookup_contact_info_by_gossip_addr(&addr))
.map_or(false, |entrypoint| entrypoint.shred_version() == 0)
.is_some_and(|entrypoint| entrypoint.shred_version() == 0)
});

if all_zero_shred_versions {
Expand Down
2 changes: 1 addition & 1 deletion wen-restart/src/wen_restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ fn is_over_stake_threshold(
epoch_info_vec
.iter()
.find(|info| info.epoch == epoch)
.map_or(false, |info| {
.is_some_and(|info| {
let threshold = info
.actively_voting_stake
.checked_sub((info.total_stake as f64 * HEAVIEST_FORK_THRESHOLD_DELTA) as u64)
Expand Down

0 comments on commit 3cb2ba7

Please sign in to comment.