Skip to content

Commit 122b387

Browse files
author
Ed Page
committed
Add ASCII fast path from rust-lang
See rust-lang/rust's `src/librustc_lexer/src/lib.rs` Idea came from #13
1 parent 4c762c1 commit 122b387

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,19 @@ pub trait UnicodeXID {
7474
impl UnicodeXID for char {
7575
#[inline]
7676
fn is_xid_start(self) -> bool {
77-
derived_property::XID_Start(self)
77+
// Fast-path for ascii idents
78+
('a' <= self && self <= 'z')
79+
|| ('A' <= self && self <= 'Z')
80+
|| (self > '\x7f' && derived_property::XID_Start(self))
7881
}
7982

8083
#[inline]
8184
fn is_xid_continue(self) -> bool {
82-
derived_property::XID_Continue(self)
85+
// Fast-path for ascii idents
86+
('a' <= self && self <= 'z')
87+
|| ('A' <= self && self <= 'Z')
88+
|| ('0' <= self && self <= '9')
89+
|| self == '_'
90+
|| (self > '\x7f' && derived_property::XID_Continue(self))
8391
}
8492
}

0 commit comments

Comments
 (0)