File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -907,6 +907,12 @@ impl TokenTreeCursor {
907
907
pub fn bump ( & mut self ) {
908
908
self . index += 1 ;
909
909
}
910
+
911
+ // For skipping ahead in rare circumstances.
912
+ #[ inline]
913
+ pub fn bump_to_end ( & mut self ) {
914
+ self . index = self . stream . len ( ) ;
915
+ }
910
916
}
911
917
912
918
/// A `TokenStream` cursor that produces `Token`s. It's a bit odd that
Original file line number Diff line number Diff line change @@ -1389,15 +1389,26 @@ impl<'a> Parser<'a> {
1389
1389
// matching `CloseDelim` we are *after* the delimited sequence,
1390
1390
// i.e. at depth `d - 1`.
1391
1391
let target_depth = self . token_cursor . stack . len ( ) - 1 ;
1392
- loop {
1393
- // Advance one token at a time, so `TokenCursor::next()`
1394
- // can capture these tokens if necessary.
1392
+
1393
+ if let Capturing :: No = self . capture_state . capturing {
1394
+ // We are not capturing tokens, so skip to the end of the
1395
+ // delimited sequence. This is a perf win when dealing with
1396
+ // declarative macros that pass large `tt` fragments through
1397
+ // multiple rules, as seen in the uom-0.37.0 crate.
1398
+ self . token_cursor . curr . bump_to_end ( ) ;
1395
1399
self . bump ( ) ;
1396
- if self . token_cursor . stack . len ( ) == target_depth {
1397
- debug_assert ! ( self . token. kind. close_delim( ) . is_some( ) ) ;
1398
- break ;
1400
+ debug_assert_eq ! ( self . token_cursor. stack. len( ) , target_depth) ;
1401
+ } else {
1402
+ loop {
1403
+ // Advance one token at a time, so `TokenCursor::next()`
1404
+ // can capture these tokens if necessary.
1405
+ self . bump ( ) ;
1406
+ if self . token_cursor . stack . len ( ) == target_depth {
1407
+ break ;
1408
+ }
1399
1409
}
1400
1410
}
1411
+ debug_assert ! ( self . token. kind. close_delim( ) . is_some( ) ) ;
1401
1412
1402
1413
// Consume close delimiter
1403
1414
self . bump ( ) ;
You can’t perform that action at this time.
0 commit comments