Move iter_results to dyn FnMut rather than a generic
This means that we're no longer generating the iteration/locking code for each invocation site of iter_results, rather just once per query. This is a 15% win in instruction counts when compiling the rustc_query_impl crate.
This commit is contained in:
parent
c488f15700
commit
a1d7367429
5 changed files with 53 additions and 47 deletions
|
@ -49,13 +49,11 @@ pub trait QueryCache: QueryStorage {
|
|||
index: DepNodeIndex,
|
||||
) -> Self::Stored;
|
||||
|
||||
fn iter<R>(
|
||||
fn iter(
|
||||
&self,
|
||||
shards: &Sharded<Self::Sharded>,
|
||||
f: impl for<'a> FnOnce(
|
||||
&'a mut dyn Iterator<Item = (&'a Self::Key, &'a Self::Value, DepNodeIndex)>,
|
||||
) -> R,
|
||||
) -> R;
|
||||
f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex),
|
||||
);
|
||||
}
|
||||
|
||||
pub struct DefaultCacheSelector;
|
||||
|
@ -124,14 +122,17 @@ where
|
|||
value
|
||||
}
|
||||
|
||||
fn iter<R>(
|
||||
fn iter(
|
||||
&self,
|
||||
shards: &Sharded<Self::Sharded>,
|
||||
f: impl for<'a> FnOnce(&'a mut dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)>) -> R,
|
||||
) -> R {
|
||||
f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex),
|
||||
) {
|
||||
let shards = shards.lock_shards();
|
||||
let mut results = shards.iter().flat_map(|shard| shard.iter()).map(|(k, v)| (k, &v.0, v.1));
|
||||
f(&mut results)
|
||||
for shard in shards.iter() {
|
||||
for (k, v) in shard.iter() {
|
||||
f(k, &v.0, v.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,13 +208,16 @@ where
|
|||
&value.0
|
||||
}
|
||||
|
||||
fn iter<R>(
|
||||
fn iter(
|
||||
&self,
|
||||
shards: &Sharded<Self::Sharded>,
|
||||
f: impl for<'a> FnOnce(&'a mut dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)>) -> R,
|
||||
) -> R {
|
||||
f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex),
|
||||
) {
|
||||
let shards = shards.lock_shards();
|
||||
let mut results = shards.iter().flat_map(|shard| shard.iter()).map(|(k, v)| (k, &v.0, v.1));
|
||||
f(&mut results)
|
||||
for shard in shards.iter() {
|
||||
for (k, v) in shard.iter() {
|
||||
f(k, &v.0, v.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,12 +73,7 @@ impl<C: QueryCache> QueryCacheStore<C> {
|
|||
(QueryLookup { key_hash, shard }, lock)
|
||||
}
|
||||
|
||||
pub fn iter_results<R>(
|
||||
&self,
|
||||
f: impl for<'a> FnOnce(
|
||||
&'a mut dyn Iterator<Item = (&'a C::Key, &'a C::Value, DepNodeIndex)>,
|
||||
) -> R,
|
||||
) -> R {
|
||||
pub fn iter_results(&self, f: &mut dyn FnMut(&C::Key, &C::Value, DepNodeIndex)) {
|
||||
self.cache.iter(&self.shards, f)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue