@@ -273,21 +273,13 @@ where
273273 /// Close a directory. You cannot perform operations on an open directory
274274 /// and so must close it if you want to do something with it.
275275 pub fn close_dir ( & mut self , directory : Directory ) -> Result < ( ) , Error < D :: Error > > {
276- let mut found_idx = None ;
277276 for ( idx, info) in self . open_dirs . iter ( ) . enumerate ( ) {
278277 if directory == info. directory_id {
279- found_idx = Some ( idx) ;
280- break ;
281- }
282- }
283-
284- match found_idx {
285- None => Err ( Error :: BadHandle ) ,
286- Some ( idx) => {
287278 self . open_dirs . swap_remove ( idx) ;
288- Ok ( ( ) )
279+ return Ok ( ( ) ) ;
289280 }
290281 }
282+ Err ( Error :: BadHandle )
291283 }
292284
293285 /// Close a volume
@@ -357,6 +349,7 @@ where
357349 dir_entry : DirEntry ,
358350 mode : Mode ,
359351 ) -> Result < File , Error < D :: Error > > {
352+ // This check is load-bearing - we do an unchecked push later.
360353 if self . open_files . is_full ( ) {
361354 return Err ( Error :: TooManyOpenFiles ) ;
362355 }
@@ -449,6 +442,7 @@ where
449442 where
450443 N : ToShortFileName ,
451444 {
445+ // This check is load-bearing - we do an unchecked push later.
452446 if self . open_files . is_full ( ) {
453447 return Err ( Error :: TooManyOpenFiles ) ;
454448 }
@@ -524,7 +518,7 @@ where
524518 dirty : false ,
525519 } ;
526520
527- // Remember this open file
521+ // Remember this open file - can't be full as we checked already
528522 unsafe {
529523 self . open_files . push_unchecked ( file) ;
530524 }
0 commit comments