rustc_query_system: simplify QueryCache::iter
Minor cleanup to reduce a small amount of complexity and code bloat. Reduces the number of mono items in rustc_query_impl by 15%.
This commit is contained in:
parent
45b3c28518
commit
adcbe49b16
2 changed files with 17 additions and 22 deletions
|
@ -49,12 +49,11 @@ pub trait QueryCache: QueryStorage {
|
||||||
index: DepNodeIndex,
|
index: DepNodeIndex,
|
||||||
) -> Self::Stored;
|
) -> Self::Stored;
|
||||||
|
|
||||||
fn iter<R, L>(
|
fn iter<R>(
|
||||||
&self,
|
&self,
|
||||||
shards: &Sharded<L>,
|
shards: &Sharded<Self::Sharded>,
|
||||||
get_shard: impl Fn(&mut L) -> &mut Self::Sharded,
|
|
||||||
f: impl for<'a> FnOnce(
|
f: impl for<'a> FnOnce(
|
||||||
Box<dyn Iterator<Item = (&'a Self::Key, &'a Self::Value, DepNodeIndex)> + 'a>,
|
&'a mut dyn Iterator<Item = (&'a Self::Key, &'a Self::Value, DepNodeIndex)>,
|
||||||
) -> R,
|
) -> R,
|
||||||
) -> R;
|
) -> R;
|
||||||
}
|
}
|
||||||
|
@ -125,16 +124,14 @@ where
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iter<R, L>(
|
fn iter<R>(
|
||||||
&self,
|
&self,
|
||||||
shards: &Sharded<L>,
|
shards: &Sharded<Self::Sharded>,
|
||||||
get_shard: impl Fn(&mut L) -> &mut Self::Sharded,
|
f: impl for<'a> FnOnce(&'a mut dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)>) -> R,
|
||||||
f: impl for<'a> FnOnce(Box<dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)> + 'a>) -> R,
|
|
||||||
) -> R {
|
) -> R {
|
||||||
let mut shards = shards.lock_shards();
|
let shards = shards.lock_shards();
|
||||||
let mut shards: Vec<_> = shards.iter_mut().map(|shard| get_shard(shard)).collect();
|
let mut results = shards.iter().flat_map(|shard| shard.iter()).map(|(k, v)| (k, &v.0, v.1));
|
||||||
let results = shards.iter_mut().flat_map(|shard| shard.iter()).map(|(k, v)| (k, &v.0, v.1));
|
f(&mut results)
|
||||||
f(Box::new(results))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,15 +207,13 @@ where
|
||||||
&value.0
|
&value.0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn iter<R, L>(
|
fn iter<R>(
|
||||||
&self,
|
&self,
|
||||||
shards: &Sharded<L>,
|
shards: &Sharded<Self::Sharded>,
|
||||||
get_shard: impl Fn(&mut L) -> &mut Self::Sharded,
|
f: impl for<'a> FnOnce(&'a mut dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)>) -> R,
|
||||||
f: impl for<'a> FnOnce(Box<dyn Iterator<Item = (&'a K, &'a V, DepNodeIndex)> + 'a>) -> R,
|
|
||||||
) -> R {
|
) -> R {
|
||||||
let mut shards = shards.lock_shards();
|
let shards = shards.lock_shards();
|
||||||
let mut shards: Vec<_> = shards.iter_mut().map(|shard| get_shard(shard)).collect();
|
let mut results = shards.iter().flat_map(|shard| shard.iter()).map(|(k, v)| (k, &v.0, v.1));
|
||||||
let results = shards.iter_mut().flat_map(|shard| shard.iter()).map(|(k, v)| (k, &v.0, v.1));
|
f(&mut results)
|
||||||
f(Box::new(results))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,10 +76,10 @@ impl<C: QueryCache> QueryCacheStore<C> {
|
||||||
pub fn iter_results<R>(
|
pub fn iter_results<R>(
|
||||||
&self,
|
&self,
|
||||||
f: impl for<'a> FnOnce(
|
f: impl for<'a> FnOnce(
|
||||||
Box<dyn Iterator<Item = (&'a C::Key, &'a C::Value, DepNodeIndex)> + 'a>,
|
&'a mut dyn Iterator<Item = (&'a C::Key, &'a C::Value, DepNodeIndex)>,
|
||||||
) -> R,
|
) -> R,
|
||||||
) -> R {
|
) -> R {
|
||||||
self.cache.iter(&self.shards, |shard| &mut *shard, f)
|
self.cache.iter(&self.shards, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue