@@ -226,7 +226,7 @@ pub struct RecursivePathSource<'gctx> {
226
226
/// Whether this source has loaded all package information it may contain.
227
227
loaded : bool ,
228
228
/// Packages that this sources has discovered.
229
- packages : Vec < Package > ,
229
+ packages : HashMap < PackageId , Package > ,
230
230
gctx : & ' gctx GlobalContext ,
231
231
}
232
232
@@ -244,7 +244,7 @@ impl<'gctx> RecursivePathSource<'gctx> {
244
244
source_id,
245
245
path : root. to_path_buf ( ) ,
246
246
loaded : false ,
247
- packages : Vec :: new ( ) ,
247
+ packages : Default :: default ( ) ,
248
248
gctx,
249
249
}
250
250
}
@@ -253,7 +253,7 @@ impl<'gctx> RecursivePathSource<'gctx> {
253
253
/// filesystem if package information haven't yet loaded.
254
254
pub fn read_packages ( & mut self ) -> CargoResult < Vec < Package > > {
255
255
self . load ( ) ?;
256
- Ok ( self . packages . clone ( ) )
256
+ Ok ( self . packages . iter ( ) . map ( | ( _ , v ) | v . clone ( ) ) . collect ( ) )
257
257
}
258
258
259
259
/// List all files relevant to building this package inside this source.
@@ -311,7 +311,7 @@ impl<'gctx> Source for RecursivePathSource<'gctx> {
311
311
f : & mut dyn FnMut ( IndexSummary ) ,
312
312
) -> Poll < CargoResult < ( ) > > {
313
313
self . load ( ) ?;
314
- for s in self . packages . iter ( ) . map ( |p| p. summary ( ) ) {
314
+ for s in self . packages . values ( ) . map ( |p| p. summary ( ) ) {
315
315
let matched = match kind {
316
316
QueryKind :: Exact => dep. matches ( s) ,
317
317
QueryKind :: Alternatives => true ,
@@ -339,7 +339,7 @@ impl<'gctx> Source for RecursivePathSource<'gctx> {
339
339
fn download ( & mut self , id : PackageId ) -> CargoResult < MaybePackage > {
340
340
trace ! ( "getting packages; id={}" , id) ;
341
341
self . load ( ) ?;
342
- let pkg = self . packages . iter ( ) . find ( |pkg| pkg . package_id ( ) == id) ;
342
+ let pkg = self . packages . get ( & id) ;
343
343
pkg. cloned ( )
344
344
. map ( MaybePackage :: Ready )
345
345
. ok_or_else ( || internal ( format ! ( "failed to find {} in path source" , id) ) )
@@ -758,7 +758,7 @@ fn read_packages(
758
758
path : & Path ,
759
759
source_id : SourceId ,
760
760
gctx : & GlobalContext ,
761
- ) -> CargoResult < Vec < Package > > {
761
+ ) -> CargoResult < HashMap < PackageId , Package > > {
762
762
let mut all_packages = HashMap :: new ( ) ;
763
763
let mut visited = HashSet :: < PathBuf > :: new ( ) ;
764
764
let mut errors = Vec :: < anyhow:: Error > :: new ( ) ;
@@ -823,7 +823,7 @@ fn read_packages(
823
823
}
824
824
}
825
825
} else {
826
- Ok ( all_packages. into_iter ( ) . map ( | ( _ , v ) | v ) . collect ( ) )
826
+ Ok ( all_packages)
827
827
}
828
828
}
829
829
0 commit comments