Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir_def/src/dyn_map.rs')
-rw-r--r--crates/hir_def/src/dyn_map.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/crates/hir_def/src/dyn_map.rs b/crates/hir_def/src/dyn_map.rs
index 6f269d7b01..166aa04da0 100644
--- a/crates/hir_def/src/dyn_map.rs
+++ b/crates/hir_def/src/dyn_map.rs
@@ -54,6 +54,7 @@ pub trait Policy {
fn insert(map: &mut DynMap, key: Self::K, value: Self::V);
fn get<'a>(map: &'a DynMap, key: &Self::K) -> Option<&'a Self::V>;
+ fn is_empty(map: &DynMap) -> bool;
}
impl<K: Hash + Eq + 'static, V: 'static> Policy for (K, V) {
@@ -65,6 +66,9 @@ impl<K: Hash + Eq + 'static, V: 'static> Policy for (K, V) {
fn get<'a>(map: &'a DynMap, key: &K) -> Option<&'a V> {
map.map.get::<FxHashMap<K, V>>()?.get(key)
}
+ fn is_empty(map: &DynMap) -> bool {
+ map.map.get::<FxHashMap<K, V>>().map_or(true, |it| it.is_empty())
+ }
}
pub struct DynMap {
@@ -90,6 +94,10 @@ impl<P: Policy> KeyMap<Key<P::K, P::V, P>> {
pub fn get(&self, key: &P::K) -> Option<&P::V> {
P::get(&self.map, key)
}
+
+ pub fn is_empty(&self) -> bool {
+ P::is_empty(&self.map)
+ }
}
impl<P: Policy> Index<Key<P::K, P::V, P>> for DynMap {