File tree 1 file changed +9
-7
lines changed
1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -651,16 +651,18 @@ impl<T> TrieMap<T> {
651
651
652
652
let child = & current. children [ child_idx] ;
653
653
if delete_child && child. data_idx . is_none ( ) && child. children . is_empty ( ) {
654
- let mut new_children = Vec :: with_capacity ( current. children . len ( ) - 1 ) ;
655
- for i in 0 ..current. children . len ( ) {
654
+ let current_size = current. children . len ( ) ;
655
+ let mut new_children = self . pool . get ( current_size - 1 ) ;
656
+ let mut new_idx = 0 ;
657
+
658
+ for i in 0 ..current_size {
656
659
if i != child_idx {
657
- new_children. push ( std:: mem:: replace (
658
- & mut current. children [ i] ,
659
- TrieNode :: new ( ) ,
660
- ) ) ;
660
+ mem:: swap ( & mut new_children[ new_idx] , & mut current. children [ i] ) ;
661
+ new_idx += 1 ;
661
662
}
662
663
}
663
- current. children = new_children. into_boxed_slice ( ) ;
664
+ let old_children = mem:: replace ( & mut current. children , new_children) ;
665
+ self . pool . put ( old_children) ;
664
666
665
667
clear_bit ( & mut current. is_present , byte) ;
666
668
You can’t perform that action at this time.
0 commit comments