Skip to content

Commit

Permalink
Rollup merge of rust-lang#87499 - ibraheemdev:patch-6, r=dtolnay
Browse files Browse the repository at this point in the history
Remove ASCII fast path from `rustc_lexer::{is_id_continue, is_id_start}`

`unicode_xid` now has a fast path built-in: unicode-rs/unicode-xid@122b387
  • Loading branch information
JohnTitor authored Jul 27, 2021
2 parents 282ac09 + de27d68 commit 84962a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5409,9 +5409,9 @@ dependencies = [

[[package]]
name = "unicode-xid"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"

[[package]]
name = "unicode_categories"
Expand Down
14 changes: 2 additions & 12 deletions compiler/rustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,24 +273,14 @@ pub fn is_whitespace(c: char) -> bool {
/// a formal definition of valid identifier name.
pub fn is_id_start(c: char) -> bool {
// This is XID_Start OR '_' (which formally is not a XID_Start).
// We also add fast-path for ascii idents
('a'..='z').contains(&c)
|| ('A'..='Z').contains(&c)
|| c == '_'
|| (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_start(c))
c == '_' || unicode_xid::UnicodeXID::is_xid_start(c)
}

/// True if `c` is valid as a non-first character of an identifier.
/// See [Rust language reference](https://doc.rust-lang.org/reference/identifiers.html) for
/// a formal definition of valid identifier name.
pub fn is_id_continue(c: char) -> bool {
// This is exactly XID_Continue.
// We also add fast-path for ascii idents
('a'..='z').contains(&c)
|| ('A'..='Z').contains(&c)
|| ('0'..='9').contains(&c)
|| c == '_'
|| (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_continue(c))
unicode_xid::UnicodeXID::is_xid_continue(c)
}

/// The passed string is lexically an identifier.
Expand Down

0 comments on commit 84962a7

Please sign in to comment.