File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121 . find ( |( _, child) | child. size > size) ;
2222 if let Some ( ( index, _) ) = excess_child {
2323 let path = once ( name) . collect ( ) ;
24- let mut children = children;
25- let child = children. swap_remove ( index) ; // this still does the unnecessary work of swapping the elements, how to skip it?
24+ let child = keep_one ( children, index) . expect ( "excess child" ) ;
2625 return Err ( ConversionError :: ExcessiveChildren { path, size, child } ) ;
2726 }
2827 let children: Result < Vec < _ > , _ > = children
8988 } )
9089 }
9190}
91+
92+ /// Extract an item at `index` if it exists. Then drop all remaining items.
93+ #[ inline]
94+ fn keep_one < Item > ( vec : Vec < Item > , index : usize ) -> Option < Item > {
95+ // worry not about performance, for `vec.advanced_by` is overridden with O(1) algorithm
96+ vec. into_iter ( ) . nth ( index)
97+ }
You can’t perform that action at this time.
0 commit comments