Skip to content

Commit 5b2075e

Browse files
committed
Remove TokenTreesReader::bump.
It's an unnecessary layer that obfuscates when I am looking for optimizations.
1 parent d7928a9 commit 5b2075e

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

compiler/rustc_parse/src/lexer/tokentrees.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ struct TokenTreesReader<'a> {
4545
impl<'a> TokenTreesReader<'a> {
4646
// Parse a stream of tokens into a list of `TokenTree`s, up to an `Eof`.
4747
fn parse_all_token_trees(&mut self) -> PResult<'a, TokenStream> {
48+
self.token = self.string_reader.next_token().0;
4849
let mut buf = TokenStreamBuilder::default();
49-
50-
self.bump();
5150
loop {
5251
match self.token.kind {
5352
token::OpenDelim(delim) => buf.push(self.parse_token_tree_open_delim(delim)),
@@ -116,7 +115,7 @@ impl<'a> TokenTreesReader<'a> {
116115

117116
// Parse the open delimiter.
118117
self.open_braces.push((delim, self.token.span));
119-
self.bump();
118+
self.token = self.string_reader.next_token().0;
120119

121120
// Parse the token trees within the delimiters.
122121
// We stop at any delimiter so we can try to recover if the user
@@ -155,7 +154,7 @@ impl<'a> TokenTreesReader<'a> {
155154
self.matching_delim_spans.push((open_brace, open_brace_span, close_brace_span));
156155
}
157156
// Parse the closing delimiter.
158-
self.bump();
157+
self.token = self.string_reader.next_token().0;
159158
}
160159
// Incorrect delimiter.
161160
token::CloseDelim(other) => {
@@ -202,7 +201,7 @@ impl<'a> TokenTreesReader<'a> {
202201
// bar(baz(
203202
// } // Incorrect delimiter but matches the earlier `{`
204203
if !self.open_braces.iter().any(|&(b, _)| b == other) {
205-
self.bump();
204+
self.token = self.string_reader.next_token().0;
206205
}
207206
}
208207
token::Eof => {
@@ -248,22 +247,15 @@ impl<'a> TokenTreesReader<'a> {
248247
fn parse_token_tree_other(&mut self) -> TokenTree {
249248
// `spacing` for the returned token is determined by the next token:
250249
// its kind and its `preceded_by_whitespace` status.
251-
let tok = self.token.take();
252-
let is_next_tok_preceded_by_whitespace = self.bump();
253-
let spacing = if is_next_tok_preceded_by_whitespace || !self.token.is_op() {
250+
let this_tok = self.token.take();
251+
let (next_tok, is_next_tok_preceded_by_whitespace) = self.string_reader.next_token();
252+
let this_spacing = if is_next_tok_preceded_by_whitespace || !next_tok.is_op() {
254253
Spacing::Alone
255254
} else {
256255
Spacing::Joint
257256
};
258-
TokenTree::Token(tok, spacing)
259-
}
260-
261-
// Set `self.token` to the next token. Returns a bool indicating if that
262-
// token was preceded by whitespace.
263-
fn bump(&mut self) -> bool {
264-
let (token, spacing) = self.string_reader.next_token();
265-
self.token = token;
266-
spacing
257+
self.token = next_tok;
258+
TokenTree::Token(this_tok, this_spacing)
267259
}
268260
}
269261

0 commit comments

Comments
 (0)