Skip to content

Commit

Permalink
optimize cursor bumping in the lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
the8472 committed Aug 29, 2023
1 parent f896f50 commit 41fc4b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion compiler/rustc_lexer/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,17 @@ impl<'a> Cursor<'a> {
// It was tried making optimized version of this for eg. line comments, but
// LLVM can inline all of this and compile it down to fast iteration over bytes.
while predicate(self.first()) && !self.is_eof() {
self.bump();
#[cfg(debug_assertions)]
{
self.bump();
}

#[cfg(not(debug_assertions))]
{
// SAFETY: we checked it's not EOF therefore there must be
// at least 1 char present.
unsafe { self.chars.advance_by(1).unwrap_unchecked() };
}
}
}
}
1 change: 1 addition & 0 deletions compiler/rustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! lexeme types.
//!
//! [`rustc_parse::lexer`]: ../rustc_parse/lexer/index.html
#![feature(iter_advance_by)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
// We want to be able to build this crate with a stable compiler, so no
Expand Down

0 comments on commit 41fc4b9

Please sign in to comment.