@@ -28,8 +28,13 @@ pub trait QueryCache: Sized {
2828 /// value by executing the query or loading a cached value from disk.
2929 fn complete ( & self , key : Self :: Key , value : Self :: Value , index : DepNodeIndex ) ;
3030
31- fn iter ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) ;
31+ /// Calls a closure on each entry in this cache.
32+ fn for_each ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) ;
3233
34+ /// Returns the number of entries currently in this cache.
35+ ///
36+ /// Useful for reserving capacity in data structures that will hold the
37+ /// output of a call to [`Self::for_each`].
3338 fn len ( & self ) -> usize ;
3439}
3540
6570 self . cache . insert ( key, ( value, index) ) ;
6671 }
6772
68- fn iter ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
73+ fn for_each ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
6974 for shard in self . cache . lock_shards ( ) {
7075 for ( k, v) in shard. iter ( ) {
7176 f ( k, & v. 0 , v. 1 ) ;
@@ -107,7 +112,7 @@ where
107112 self . cache . set ( ( value, index) ) . ok ( ) ;
108113 }
109114
110- fn iter ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
115+ fn for_each ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
111116 if let Some ( value) = self . cache . get ( ) {
112117 f ( & ( ) , & value. 0 , value. 1 )
113118 }
@@ -160,11 +165,11 @@ where
160165 }
161166 }
162167
163- fn iter ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
164- self . local . iter ( & mut |key, value, index| {
168+ fn for_each ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
169+ self . local . for_each ( & mut |key, value, index| {
165170 f ( & DefId { krate : LOCAL_CRATE , index : * key } , value, index) ;
166171 } ) ;
167- self . foreign . iter ( f) ;
172+ self . foreign . for_each ( f) ;
168173 }
169174
170175 fn len ( & self ) -> usize {
@@ -190,8 +195,8 @@ where
190195 self . complete ( key, value, index)
191196 }
192197
193- fn iter ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
194- self . iter ( f)
198+ fn for_each ( & self , f : & mut dyn FnMut ( & Self :: Key , & Self :: Value , DepNodeIndex ) ) {
199+ self . for_each ( f)
195200 }
196201
197202 fn len ( & self ) -> usize {
0 commit comments