@@ -206,8 +206,9 @@ struct TokenCursor {
206
206
frame : TokenCursorFrame ,
207
207
stack : Vec < TokenCursorFrame > ,
208
208
desugar_doc_comments : bool ,
209
- // Counts the number of calls to `next` or `next_desugared`,
210
- // depending on whether `desugar_doc_comments` is set.
209
+ // Counts the number of calls to `{,inlined_}next` or
210
+ // `{,inlined_}next_desugared`, depending on whether
211
+ // `desugar_doc_comments` is set.
211
212
num_next_calls : usize ,
212
213
// During parsing, we may sometimes need to 'unglue' a
213
214
// glued token into two component tokens
@@ -256,6 +257,12 @@ impl TokenCursorFrame {
256
257
257
258
impl TokenCursor {
258
259
fn next ( & mut self ) -> ( Token , Spacing ) {
260
+ self . inlined_next ( )
261
+ }
262
+
263
+ /// This always-inlined version should only be used on hot code paths.
264
+ #[ inline( always) ]
265
+ fn inlined_next ( & mut self ) -> ( Token , Spacing ) {
259
266
loop {
260
267
let ( tree, spacing) = if !self . frame . open_delim {
261
268
self . frame . open_delim = true ;
@@ -285,7 +292,13 @@ impl TokenCursor {
285
292
}
286
293
287
294
fn next_desugared ( & mut self ) -> ( Token , Spacing ) {
288
- let ( data, attr_style, sp) = match self . next ( ) {
295
+ self . inlined_next_desugared ( )
296
+ }
297
+
298
+ /// This always-inlined version should only be used on hot code paths.
299
+ #[ inline( always) ]
300
+ fn inlined_next_desugared ( & mut self ) -> ( Token , Spacing ) {
301
+ let ( data, attr_style, sp) = match self . inlined_next ( ) {
289
302
( Token { kind : token:: DocComment ( _, attr_style, data) , span } , _) => {
290
303
( data, attr_style, span)
291
304
}
@@ -463,12 +476,13 @@ impl<'a> Parser<'a> {
463
476
parser
464
477
}
465
478
479
+ #[ inline]
466
480
fn next_tok ( & mut self , fallback_span : Span ) -> ( Token , Spacing ) {
467
481
loop {
468
482
let ( mut next, spacing) = if self . desugar_doc_comments {
469
- self . token_cursor . next_desugared ( )
483
+ self . token_cursor . inlined_next_desugared ( )
470
484
} else {
471
- self . token_cursor . next ( )
485
+ self . token_cursor . inlined_next ( )
472
486
} ;
473
487
self . token_cursor . num_next_calls += 1 ;
474
488
// We've retrieved an token from the underlying
@@ -998,7 +1012,13 @@ impl<'a> Parser<'a> {
998
1012
}
999
1013
1000
1014
/// Advance the parser by one token using provided token as the next one.
1001
- fn bump_with ( & mut self , ( next_token, next_spacing) : ( Token , Spacing ) ) {
1015
+ fn bump_with ( & mut self , next : ( Token , Spacing ) ) {
1016
+ self . inlined_bump_with ( next)
1017
+ }
1018
+
1019
+ /// This always-inlined version should only be used on hot code paths.
1020
+ #[ inline( always) ]
1021
+ fn inlined_bump_with ( & mut self , ( next_token, next_spacing) : ( Token , Spacing ) ) {
1002
1022
// Bumping after EOF is a bad sign, usually an infinite loop.
1003
1023
if self . prev_token . kind == TokenKind :: Eof {
1004
1024
let msg = "attempted to bump the parser past EOF (may be stuck in a loop)" ;
@@ -1016,7 +1036,7 @@ impl<'a> Parser<'a> {
1016
1036
/// Advance the parser by one token.
1017
1037
pub fn bump ( & mut self ) {
1018
1038
let next_token = self . next_tok ( self . token . span ) ;
1019
- self . bump_with ( next_token) ;
1039
+ self . inlined_bump_with ( next_token) ;
1020
1040
}
1021
1041
1022
1042
/// Look-ahead `dist` tokens of `self.token` and get access to that token there.
0 commit comments