mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Use with_capacity in query_key_hash_verify
This commit is contained in:
@@ -331,6 +331,10 @@ pub fn iter(&self, f: &mut dyn FnMut(&K, &V, I)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.len.load(Ordering::Acquire)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -415,9 +415,8 @@ pub(crate) fn query_key_hash_verify<'tcx>(
|
||||
) {
|
||||
let _timer = qcx.tcx.prof.generic_activity_with_arg("query_key_hash_verify_for", query.name());
|
||||
|
||||
let mut map = UnordMap::default();
|
||||
|
||||
let cache = query.query_cache(qcx);
|
||||
let mut map = UnordMap::with_capacity(cache.len());
|
||||
cache.iter(&mut |key, _, _| {
|
||||
let node = DepNode::construct(qcx.tcx, query.dep_kind(), key);
|
||||
if let Some(other_key) = map.insert(node, *key) {
|
||||
|
||||
@@ -30,6 +30,8 @@ pub trait QueryCache: Sized {
|
||||
fn complete(&self, key: Self::Key, value: Self::Value, index: DepNodeIndex);
|
||||
|
||||
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex));
|
||||
|
||||
fn len(&self) -> usize;
|
||||
}
|
||||
|
||||
/// In-memory cache for queries whose keys aren't suitable for any of the
|
||||
@@ -71,6 +73,10 @@ fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.cache.len()
|
||||
}
|
||||
}
|
||||
|
||||
/// In-memory cache for queries whose key type only has one value (e.g. `()`).
|
||||
@@ -107,6 +113,10 @@ fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
|
||||
f(&(), &value.0, value.1)
|
||||
}
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.cache.get().is_some().into()
|
||||
}
|
||||
}
|
||||
|
||||
/// In-memory cache for queries whose key is a [`DefId`].
|
||||
@@ -157,6 +167,10 @@ fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
|
||||
});
|
||||
self.foreign.iter(f);
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.local.len() + self.foreign.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> QueryCache for VecCache<K, V, DepNodeIndex>
|
||||
@@ -180,4 +194,8 @@ fn complete(&self, key: K, value: V, index: DepNodeIndex) {
|
||||
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
|
||||
self.iter(f)
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.len()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user