@@ -206,8 +206,9 @@ struct TokenCursor {
206206 frame : TokenCursorFrame ,
207207 stack : Vec < TokenCursorFrame > ,
208208 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.
211212 num_next_calls : usize ,
212213 // During parsing, we may sometimes need to 'unglue' a
213214 // glued token into two component tokens
@@ -256,6 +257,12 @@ impl TokenCursorFrame {
256257
257258impl TokenCursor {
258259 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 ) {
259266 loop {
260267 let ( tree, spacing) = if !self . frame . open_delim {
261268 self . frame . open_delim = true ;
@@ -285,7 +292,13 @@ impl TokenCursor {
285292 }
286293
287294 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 ( ) {
289302 ( Token { kind : token:: DocComment ( _, attr_style, data) , span } , _) => {
290303 ( data, attr_style, span)
291304 }
@@ -467,9 +480,9 @@ impl<'a> Parser<'a> {
467480 fn next_tok ( & mut self , fallback_span : Span ) -> ( Token , Spacing ) {
468481 loop {
469482 let ( mut next, spacing) = if self . desugar_doc_comments {
470- self . token_cursor . next_desugared ( )
483+ self . token_cursor . inlined_next_desugared ( )
471484 } else {
472- self . token_cursor . next ( )
485+ self . token_cursor . inlined_next ( )
473486 } ;
474487 self . token_cursor . num_next_calls += 1 ;
475488 // We've retrieved an token from the underlying
0 commit comments