Skip to content

Commit 231c29b

Browse files
committed
simplify eat_past_either logic for better readability and performance
1 parent 74caa63 commit 231c29b

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

compiler/rustc_lexer/src/cursor.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,12 @@ impl<'a> Cursor<'a> {
164164
/// Returns the found byte if any, or None if end of file was reached.
165165
pub(crate) fn eat_past_either(&mut self, byte1: u8, byte2: u8) -> Option<u8> {
166166
let bytes = self.as_str().as_bytes();
167-
match memchr::memchr2(byte1, byte2, bytes) {
168-
Some(index) => {
169-
let found = bytes[index];
170-
self.bump_bytes(index + 1);
171-
Some(found)
172-
}
173-
None => {
174-
self.chars = "".chars();
175-
None
176-
}
167+
if let Some(index) = memchr::memchr2(byte1, byte2, bytes) {
168+
let found = Some(bytes[index]);
169+
self.chars = self.as_str()[index + 1..].chars();
170+
return found;
177171
}
172+
self.chars = "".chars();
173+
None
178174
}
179175
}

0 commit comments

Comments
 (0)