@@ -171,6 +171,8 @@ fn clean_specs(
171171
172172 clean_ctx. progress = Box :: new ( CleaningPackagesBar :: new ( clean_ctx. gctx , packages. len ( ) ) ) ;
173173
174+ // Try to reduce the amount of times we iterate over the same target directory by storing away
175+ // the directories we've iterated over (and cleaned for a given package).
174176 let mut cleaned_packages: HashMap < _ , HashSet < _ > > = HashMap :: default ( ) ;
175177 for pkg in packages {
176178 let pkg_dir = format ! ( "{}-*" , pkg. name( ) ) ;
@@ -236,11 +238,8 @@ fn clean_specs(
236238 clean_ctx. rm_rf ( & dep_info) ?;
237239 }
238240 }
239- // Remove dep-info file generated by rustc. It is not tracked in
240- // file_types. It does not have a prefix.
241241 let unhashed_dep_info = dir. join ( format ! ( "{}.d" , crate_name) ) ;
242242 clean_ctx. rm_rf ( & unhashed_dep_info) ?;
243- // Remove split-debuginfo files generated by rustc.
244243
245244 if !dir_glob_str. ends_with ( std:: path:: MAIN_SEPARATOR ) {
246245 dir_glob_str. push ( std:: path:: MAIN_SEPARATOR ) ;
@@ -253,7 +252,10 @@ fn clean_specs(
253252 . insert ( crate_name. clone ( ) )
254253 {
255254 let paths = [
255+ // Remove dep-info file generated by rustc. It is not tracked in
256+ // file_types. It does not have a prefix.
256257 ( path_dash. clone ( ) , ".d" ) ,
258+ // Remove split-debuginfo files generated by rustc.
257259 ( path_dot. clone ( ) , ".o" ) ,
258260 ( path_dot. clone ( ) , ".dwo" ) ,
259261 ( path_dot. clone ( ) , ".dwp" ) ,
@@ -339,13 +341,14 @@ impl<'gctx> CleanContext<'gctx> {
339341 Ok ( ( ) )
340342 }
341343
344+ /// Iterates over files matching a glob (`pattern`), removing any files whose filenames start and end with provided prefix/suffix pair.
345+ /// Compared to multiple separate calls to [`Self::rm_rf_glob`], this method iterates over the directory just once, which is why
346+ /// it may be preferable for working with multiple prefix/suffix pairs.
342347 fn rm_rf_prefix_list (
343348 & mut self ,
344349 pattern : & str ,
345350 path_matchers : & [ ( Rc < str > , & str ) ] ,
346351 ) -> CargoResult < ( ) > {
347- // TODO: Display utf8 warning to user? Or switch to globset?
348-
349352 for path in glob:: glob ( pattern) ? {
350353 let path = path?;
351354 let filename = path. file_name ( ) . and_then ( |name| name. to_str ( ) ) . unwrap ( ) ;
0 commit comments