@@ -203,17 +203,16 @@ impl BindingsBuilder {
203
203
}
204
204
205
205
fn build ( self , idx : & BindingsIdx ) -> Bindings {
206
- let mut bindings = Bindings :: default ( ) ;
207
- self . build_inner ( & mut bindings, & self . nodes [ idx. 0 ] ) ;
208
- bindings
206
+ self . build_inner ( & self . nodes [ idx. 0 ] )
209
207
}
210
208
211
- fn build_inner ( & self , bindings : & mut Bindings , link_nodes : & [ LinkNode < Rc < BindingKind > > ] ) {
209
+ fn build_inner ( & self , link_nodes : & [ LinkNode < Rc < BindingKind > > ] ) -> Bindings {
210
+ let mut bindings = Bindings :: default ( ) ;
212
211
let mut nodes = Vec :: new ( ) ;
213
212
self . collect_nodes ( link_nodes, & mut nodes) ;
214
213
215
214
for cmd in nodes {
216
- match & * * cmd {
215
+ match cmd {
217
216
BindingKind :: Empty ( name) => {
218
217
bindings. push_empty ( name) ;
219
218
}
@@ -246,13 +245,15 @@ impl BindingsBuilder {
246
245
}
247
246
}
248
247
}
248
+
249
+ bindings
249
250
}
250
251
251
252
fn collect_nested_ref < ' a > (
252
253
& ' a self ,
253
254
id : usize ,
254
255
len : usize ,
255
- nested_refs : & mut Vec < & ' a Vec < LinkNode < Rc < BindingKind > > > > ,
256
+ nested_refs : & mut Vec < & ' a [ LinkNode < Rc < BindingKind > > ] > ,
256
257
) {
257
258
self . nested [ id] . iter ( ) . take ( len) . for_each ( |it| match it {
258
259
LinkNode :: Node ( id) => nested_refs. push ( & self . nodes [ * id] ) ,
@@ -262,26 +263,16 @@ impl BindingsBuilder {
262
263
263
264
fn collect_nested ( & self , idx : usize , nested_idx : usize , nested : & mut Vec < Bindings > ) {
264
265
let last = & self . nodes [ idx] ;
265
- let mut nested_refs = Vec :: new ( ) ;
266
+ let mut nested_refs: Vec < & [ _ ] > = Vec :: new ( ) ;
266
267
self . nested [ nested_idx] . iter ( ) . for_each ( |it| match * it {
267
268
LinkNode :: Node ( idx) => nested_refs. push ( & self . nodes [ idx] ) ,
268
269
LinkNode :: Parent { idx, len } => self . collect_nested_ref ( idx, len, & mut nested_refs) ,
269
270
} ) ;
270
271
nested_refs. push ( last) ;
271
-
272
- nested_refs. into_iter ( ) . for_each ( |iter| {
273
- let mut child_bindings = Bindings :: default ( ) ;
274
- self . build_inner ( & mut child_bindings, iter) ;
275
- nested. push ( child_bindings)
276
- } )
272
+ nested. extend ( nested_refs. into_iter ( ) . map ( |iter| self . build_inner ( iter) ) ) ;
277
273
}
278
274
279
- fn collect_nodes_ref < ' a > (
280
- & ' a self ,
281
- id : usize ,
282
- len : usize ,
283
- nodes : & mut Vec < & ' a Rc < BindingKind > > ,
284
- ) {
275
+ fn collect_nodes_ref < ' a > ( & ' a self , id : usize , len : usize , nodes : & mut Vec < & ' a BindingKind > ) {
285
276
self . nodes [ id] . iter ( ) . take ( len) . for_each ( |it| match it {
286
277
LinkNode :: Node ( it) => nodes. push ( it) ,
287
278
LinkNode :: Parent { idx, len } => self . collect_nodes_ref ( * idx, * len, nodes) ,
@@ -291,7 +282,7 @@ impl BindingsBuilder {
291
282
fn collect_nodes < ' a > (
292
283
& ' a self ,
293
284
link_nodes : & ' a [ LinkNode < Rc < BindingKind > > ] ,
294
- nodes : & mut Vec < & ' a Rc < BindingKind > > ,
285
+ nodes : & mut Vec < & ' a BindingKind > ,
295
286
) {
296
287
link_nodes. iter ( ) . for_each ( |it| match it {
297
288
LinkNode :: Node ( it) => nodes. push ( it) ,
@@ -386,10 +377,10 @@ fn match_loop_inner<'t>(
386
377
let op = match item. dot . peek ( ) {
387
378
None => {
388
379
// We are at or past the end of the matcher of `item`.
389
- if item. up . is_some ( ) {
380
+ if let Some ( up ) = & item. up {
390
381
if item. sep_parsed . is_none ( ) {
391
382
// Get the `up` matcher
392
- let mut new_pos = * item . up . clone ( ) . unwrap ( ) ;
383
+ let mut new_pos = ( * * up ) . clone ( ) ;
393
384
new_pos. bindings = bindings_builder. copy ( & new_pos. bindings ) ;
394
385
// Add matches from this repetition to the `matches` of `up`
395
386
bindings_builder. push_nested ( & mut new_pos. bindings , & item. bindings ) ;
@@ -402,7 +393,7 @@ fn match_loop_inner<'t>(
402
393
403
394
// Check if we need a separator.
404
395
// We check the separator one by one
405
- let sep_idx = * item. sep_parsed . as_ref ( ) . unwrap_or ( & 0 ) ;
396
+ let sep_idx = item. sep_parsed . unwrap_or ( 0 ) ;
406
397
let sep_len = item. sep . as_ref ( ) . map_or ( 0 , Separator :: tt_count) ;
407
398
if item. sep . is_some ( ) && sep_idx != sep_len {
408
399
let sep = item. sep . as_ref ( ) . unwrap ( ) ;
0 commit comments