1
- use std:: collections:: HashMap ;
2
1
use std:: rc:: Rc ;
3
2
use dprint_core:: formatting:: * ;
4
3
use dprint_core:: formatting:: { parser_helpers:: * , condition_resolvers, conditions:: * } ;
@@ -4848,7 +4847,7 @@ fn parse_statements<'a>(inner_span: Span, stmts: Vec<Node<'a>>, context: &mut Co
4848
4847
4849
4848
let nodes_len = stmt_group. nodes . len ( ) ;
4850
4849
let mut parsed_nodes = Vec :: with_capacity ( nodes_len) ;
4851
- let mut parsed_line_separators = HashMap :: with_capacity ( if nodes_len == 0 { 0 } else { nodes_len - 1 } ) ;
4850
+ let mut parsed_line_separators = utils :: VecMap :: with_capacity ( nodes_len) ;
4852
4851
let sorter = get_node_sorter ( stmt_group. kind , context) ;
4853
4852
let sorted_indexes = match sorter {
4854
4853
Some ( sorter) => Some ( get_sorted_indexes ( stmt_group. nodes . iter ( ) . map ( |n| Some ( n) ) , sorter, context) ) ,
@@ -4897,7 +4896,7 @@ fn parse_statements<'a>(inner_span: Span, stmts: Vec<Node<'a>>, context: &mut Co
4897
4896
4898
4897
// Now combine everything
4899
4898
for ( i, parsed_node) in parsed_nodes. into_iter ( ) . enumerate ( ) {
4900
- if let Some ( parsed_separator) = parsed_line_separators. remove ( & i) {
4899
+ if let Some ( parsed_separator) = parsed_line_separators. remove ( i) {
4901
4900
items. extend ( parsed_separator) ;
4902
4901
}
4903
4902
items. extend ( parsed_node) ;
@@ -5360,7 +5359,7 @@ fn parse_separated_values_with_result<'a>(
5360
5359
5361
5360
for ( i, value) in nodes. into_iter ( ) . enumerate ( ) {
5362
5361
let node_index = match & sorted_indexes {
5363
- Some ( old_to_new_index) => * old_to_new_index. get ( & i) . unwrap ( ) ,
5362
+ Some ( old_to_new_index) => * old_to_new_index. get ( i) . unwrap ( ) ,
5364
5363
None => i,
5365
5364
} ;
5366
5365
let ( allow_inline_multi_line, allow_inline_single_line) = if let Some ( value) = & value {
@@ -5412,10 +5411,10 @@ fn get_sorted_indexes<'a: 'b, 'b>(
5412
5411
nodes : impl Iterator < Item =Option < & ' b Node < ' a > > > ,
5413
5412
sorter : Box < dyn Fn ( ( usize , Option < & Node < ' a > > ) , ( usize , Option < & Node < ' a > > ) , & Module < ' a > ) -> std:: cmp:: Ordering > ,
5414
5413
context : & mut Context < ' a > ,
5415
- ) -> HashMap < usize , usize > {
5414
+ ) -> utils :: VecMap < usize > {
5416
5415
let mut nodes_with_indexes = nodes. enumerate ( ) . collect :: < Vec < _ > > ( ) ;
5417
5416
nodes_with_indexes. sort_unstable_by ( |a, b| sorter ( ( a. 0 , a. 1 ) , ( b. 0 , b. 1 ) , context. module ) ) ;
5418
- let mut old_to_new_index = HashMap :: new ( ) ;
5417
+ let mut old_to_new_index = utils :: VecMap :: with_capacity ( nodes_with_indexes . len ( ) ) ;
5419
5418
5420
5419
for ( new_index, old_index) in nodes_with_indexes. into_iter ( ) . map ( |( index, _) | index) . enumerate ( ) {
5421
5420
old_to_new_index. insert ( old_index, new_index) ;
@@ -5424,14 +5423,14 @@ fn get_sorted_indexes<'a: 'b, 'b>(
5424
5423
old_to_new_index
5425
5424
}
5426
5425
5427
- fn sort_by_sorted_indexes < T > ( items : Vec < T > , sorted_indexes : HashMap < usize , usize > ) -> Vec < T > {
5426
+ fn sort_by_sorted_indexes < T > ( items : Vec < T > , sorted_indexes : utils :: VecMap < usize > ) -> Vec < T > {
5428
5427
let mut sorted_items = Vec :: with_capacity ( items. len ( ) ) ;
5429
5428
for _ in 0 ..items. len ( ) {
5430
5429
sorted_items. push ( None ) ;
5431
5430
}
5432
5431
5433
5432
for ( i, parsed_node) in items. into_iter ( ) . enumerate ( ) {
5434
- sorted_items[ * sorted_indexes. get ( & i) . unwrap_or ( & i) ] = Some ( parsed_node) ;
5433
+ sorted_items[ * sorted_indexes. get ( i) . unwrap_or ( & i) ] = Some ( parsed_node) ;
5435
5434
}
5436
5435
5437
5436
sorted_items. into_iter ( ) . map ( |x| x. unwrap ( ) ) . collect ( )
0 commit comments