diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-03-07 15:55:39 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-03-22 11:05:54 +1100 |
| commit | f8f1d3f00b9780e3053b15105f8ed0bfe57a5e9b (patch) | |
| tree | 72b6e9629bc5b84ca1159abefe3d04e9637fe752 /compiler/rustc_parse/src/parser/mod.rs | |
| parent | 4e700a023c2706136012c39cc30d8bf431d83f0a (diff) | |
| download | rust-f8f1d3f00b9780e3053b15105f8ed0bfe57a5e9b.tar.gz rust-f8f1d3f00b9780e3053b15105f8ed0bfe57a5e9b.zip | |
Split `TokenCursor::{next,next_desugared}` into inlined and non-inlined halves.
Diffstat (limited to 'compiler/rustc_parse/src/parser/mod.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 5c773410891..3a2f193d319 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -206,8 +206,9 @@ struct TokenCursor { frame: TokenCursorFrame, stack: Vec<TokenCursorFrame>, desugar_doc_comments: bool, - // Counts the number of calls to `next` or `next_desugared`, - // depending on whether `desugar_doc_comments` is set. + // Counts the number of calls to `{,inlined_}next` or + // `{,inlined_}next_desugared`, depending on whether + // `desugar_doc_comments` is set. num_next_calls: usize, // During parsing, we may sometimes need to 'unglue' a // glued token into two component tokens @@ -256,6 +257,12 @@ impl TokenCursorFrame { impl TokenCursor { fn next(&mut self) -> (Token, Spacing) { + self.inlined_next() + } + + /// This always-inlined version should only be used on hot code paths. + #[inline(always)] + fn inlined_next(&mut self) -> (Token, Spacing) { loop { let (tree, spacing) = if !self.frame.open_delim { self.frame.open_delim = true; @@ -285,7 +292,13 @@ impl TokenCursor { } fn next_desugared(&mut self) -> (Token, Spacing) { - let (data, attr_style, sp) = match self.next() { + self.inlined_next_desugared() + } + + /// This always-inlined version should only be used on hot code paths. + #[inline(always)] + fn inlined_next_desugared(&mut self) -> (Token, Spacing) { + let (data, attr_style, sp) = match self.inlined_next() { (Token { kind: token::DocComment(_, attr_style, data), span }, _) => { (data, attr_style, span) } @@ -467,9 +480,9 @@ impl<'a> Parser<'a> { fn next_tok(&mut self, fallback_span: Span) -> (Token, Spacing) { loop { let (mut next, spacing) = if self.desugar_doc_comments { - self.token_cursor.next_desugared() + self.token_cursor.inlined_next_desugared() } else { - self.token_cursor.next() + self.token_cursor.inlined_next() }; self.token_cursor.num_next_calls += 1; // We've retrieved an token from the underlying |
