Pass Epoch by value in StakeHistory::get() (#21523)

This commit is contained in:
Brooks Prumo
2021-12-01 08:57:29 -06:00
committed by GitHub
parent 3da914330d
commit cb368e6554
5 changed files with 12 additions and 13 deletions

View File

@ -404,7 +404,7 @@ impl Delegation {
} else if let Some((history, mut prev_epoch, mut prev_cluster_stake)) =
history.and_then(|history| {
history
.get(&self.deactivation_epoch)
.get(self.deactivation_epoch)
.map(|cluster_stake_at_deactivation_epoch| {
(
history,
@ -448,7 +448,7 @@ impl Delegation {
if current_epoch >= target_epoch {
break;
}
if let Some(current_cluster_stake) = history.get(&current_epoch) {
if let Some(current_cluster_stake) = history.get(current_epoch) {
prev_epoch = current_epoch;
prev_cluster_stake = current_cluster_stake;
} else {
@ -488,7 +488,7 @@ impl Delegation {
} else if let Some((history, mut prev_epoch, mut prev_cluster_stake)) =
history.and_then(|history| {
history
.get(&self.activation_epoch)
.get(self.activation_epoch)
.map(|cluster_stake_at_activation_epoch| {
(
history,
@ -533,7 +533,7 @@ impl Delegation {
if current_epoch >= target_epoch || current_epoch >= self.deactivation_epoch {
break;
}
if let Some(current_cluster_stake) = history.get(&current_epoch) {
if let Some(current_cluster_stake) = history.get(current_epoch) {
prev_epoch = current_epoch;
prev_cluster_stake = current_cluster_stake;
} else {

View File

@ -56,8 +56,7 @@ impl std::ops::Add for StakeHistoryEntry {
pub struct StakeHistory(Vec<(Epoch, StakeHistoryEntry)>);
impl StakeHistory {
#[allow(clippy::trivially_copy_pass_by_ref)]
pub fn get(&self, epoch: &Epoch) -> Option<&StakeHistoryEntry> {
pub fn get(&self, epoch: Epoch) -> Option<&StakeHistoryEntry> {
self.binary_search_by(|probe| epoch.cmp(&probe.0))
.ok()
.map(|index| &self[index].1)
@ -98,9 +97,9 @@ mod tests {
}
assert_eq!(stake_history.len(), MAX_ENTRIES);
assert_eq!(stake_history.iter().map(|entry| entry.0).min().unwrap(), 1);
assert_eq!(stake_history.get(&0), None);
assert_eq!(stake_history.get(0), None);
assert_eq!(
stake_history.get(&1),
stake_history.get(1),
Some(&StakeHistoryEntry {
activating: 1,
..StakeHistoryEntry::default()

View File

@ -54,9 +54,9 @@ mod tests {
}
assert_eq!(stake_history.len(), MAX_ENTRIES);
assert_eq!(stake_history.iter().map(|entry| entry.0).min().unwrap(), 1);
assert_eq!(stake_history.get(&0), None);
assert_eq!(stake_history.get(0), None);
assert_eq!(
stake_history.get(&1),
stake_history.get(1),
Some(&StakeHistoryEntry {
activating: 1,
..StakeHistoryEntry::default()