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 @@ -1388,15 +1388,26 @@ impl<'a> Parser<'a> {
1388
1388
// matching `CloseDelim` we are *after* the delimited sequence,
1389
1389
// i.e. at depth `d - 1`.
1390
1390
let target_depth = self . token_cursor . stack . len ( ) - 1 ;
1391
- loop {
1392
- // Advance one token at a time, so `TokenCursor::next()`
1393
- // can capture these tokens if necessary.
1391
+
1392
+ if let Capturing :: No = self . capture_state . capturing {
1393
+ // We are not capturing tokens, so skip to the end of the
1394
+ // delimited sequence. This is a perf win when dealing with
1395
+ // declarative macros that pass large `tt` fragments through
1396
+ // multiple rules, as seen in the uom-0.37.0 crate.
1397
+ self . token_cursor . curr . bump_to_end ( ) ;
1394
1398
self . bump ( ) ;
1395
- if self . token_cursor . stack . len ( ) == target_depth {
1396
- debug_assert ! ( self . token. kind. close_delim( ) . is_some( ) ) ;
1397
- break ;
1399
+ debug_assert_eq ! ( self . token_cursor. stack. len( ) , target_depth) ;
1400
+ } else {
1401
+ loop {
1402
+ // Advance one token at a time, so `TokenCursor::next()`
1403
+ // can capture these tokens if necessary.
1404
+ self . bump ( ) ;
1405
+ if self . token_cursor . stack . len ( ) == target_depth {
1406
+ break ;
1407
+ }
1398
1408
}
1399
1409
}
1410
+ debug_assert ! ( self . token. kind. close_delim( ) . is_some( ) ) ;
1400
1411
1401
1412
// Consume close delimiter
1402
1413
self . bump ( ) ;
You can’t perform that action at this time.
0 commit comments