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

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