From dbd2423e9f418512069c2a7b5a924f01dbad71f1 Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Tue, 16 Aug 2022 12:06:52 -0500 Subject: [PATCH] Share Ancestors API get with contains_key (#27161) consolidate similar fns --- runtime/src/ancestors.rs | 8 ++------ runtime/src/status_cache.rs | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/runtime/src/ancestors.rs b/runtime/src/ancestors.rs index 42730efd9..9712f1fdb 100644 --- a/runtime/src/ancestors.rs +++ b/runtime/src/ancestors.rs @@ -65,10 +65,6 @@ impl Ancestors { self.ancestors.get_all() } - pub fn get(&self, slot: &Slot) -> bool { - self.ancestors.contains(slot) - } - pub fn remove(&mut self, slot: &Slot) { self.ancestors.remove(slot); } @@ -182,10 +178,10 @@ pub mod tests { let key = item.0; min = std::cmp::min(min, *key); max = std::cmp::max(max, *key); - assert!(ancestors.get(key)); + assert!(ancestors.contains_key(key)); } for slot in min - 1..max + 2 { - assert_eq!(ancestors.get(&slot), hashset.contains(&slot)); + assert_eq!(ancestors.contains_key(&slot), hashset.contains(&slot)); } } diff --git a/runtime/src/status_cache.rs b/runtime/src/status_cache.rs index 130810a5f..c5d8379ce 100644 --- a/runtime/src/status_cache.rs +++ b/runtime/src/status_cache.rs @@ -137,7 +137,7 @@ impl StatusCache { if let Some(stored_forks) = keymap.get(key_slice) { let res = stored_forks .iter() - .find(|(f, _)| ancestors.get(f) || self.roots.get(f).is_some()) + .find(|(f, _)| ancestors.contains_key(f) || self.roots.get(f).is_some()) .cloned(); if res.is_some() { return res;