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 {
907907 pub fn bump ( & mut self ) {
908908 self . index += 1 ;
909909 }
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+ }
910916}
911917
912918/// 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> {
13881388 // matching `CloseDelim` we are *after* the delimited sequence,
13891389 // i.e. at depth `d - 1`.
13901390 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 ( ) ;
13941398 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+ }
13981408 }
13991409 }
1410+ debug_assert ! ( self . token. kind. close_delim( ) . is_some( ) ) ;
14001411
14011412 // Consume close delimiter
14021413 self . bump ( ) ;
You can’t perform that action at this time.
0 commit comments