@@ -273,21 +273,13 @@ where
273
273
/// Close a directory. You cannot perform operations on an open directory
274
274
/// and so must close it if you want to do something with it.
275
275
pub fn close_dir ( & mut self , directory : Directory ) -> Result < ( ) , Error < D :: Error > > {
276
- let mut found_idx = None ;
277
276
for ( idx, info) in self . open_dirs . iter ( ) . enumerate ( ) {
278
277
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) => {
287
278
self . open_dirs . swap_remove ( idx) ;
288
- Ok ( ( ) )
279
+ return Ok ( ( ) ) ;
289
280
}
290
281
}
282
+ Err ( Error :: BadHandle )
291
283
}
292
284
293
285
/// Close a volume
@@ -357,6 +349,7 @@ where
357
349
dir_entry : DirEntry ,
358
350
mode : Mode ,
359
351
) -> Result < File , Error < D :: Error > > {
352
+ // This check is load-bearing - we do an unchecked push later.
360
353
if self . open_files . is_full ( ) {
361
354
return Err ( Error :: TooManyOpenFiles ) ;
362
355
}
@@ -449,6 +442,7 @@ where
449
442
where
450
443
N : ToShortFileName ,
451
444
{
445
+ // This check is load-bearing - we do an unchecked push later.
452
446
if self . open_files . is_full ( ) {
453
447
return Err ( Error :: TooManyOpenFiles ) ;
454
448
}
@@ -524,7 +518,7 @@ where
524
518
dirty : false ,
525
519
} ;
526
520
527
- // Remember this open file
521
+ // Remember this open file - can't be full as we checked already
528
522
unsafe {
529
523
self . open_files . push_unchecked ( file) ;
530
524
}
0 commit comments