Pass Epoch by value in StakeHistory::get() (#21523)
This commit is contained in:
@ -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(¤t_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(¤t_epoch) {
|
||||
if let Some(current_cluster_stake) = history.get(current_epoch) {
|
||||
prev_epoch = current_epoch;
|
||||
prev_cluster_stake = current_cluster_stake;
|
||||
} else {
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user