diff options
author | Ed Page <epage@duosecurity.com> | 2021-04-28 10:01:26 -0500 |
---|---|---|
committer | Ed Page <epage@duosecurity.com> | 2021-04-28 10:01:30 -0500 |
commit | 122b38775cf077570025c8294280f57d2004096f (patch) | |
tree | 83c739b580ac61f3e25c24233405ed780412130b | |
parent | 4c762c188a111d8dfa79c4770a06b20236db280f (diff) | |
download | unicode-xid-122b38775cf077570025c8294280f57d2004096f.tar.gz |
Add ASCII fast path from rust-lang
See rust-lang/rust's `src/librustc_lexer/src/lib.rs`
Idea came from #13
-rw-r--r-- | src/lib.rs | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -74,11 +74,19 @@ pub trait UnicodeXID { impl UnicodeXID for char { #[inline] fn is_xid_start(self) -> bool { - derived_property::XID_Start(self) + // Fast-path for ascii idents + ('a' <= self && self <= 'z') + || ('A' <= self && self <= 'Z') + || (self > '\x7f' && derived_property::XID_Start(self)) } #[inline] fn is_xid_continue(self) -> bool { - derived_property::XID_Continue(self) + // Fast-path for ascii idents + ('a' <= self && self <= 'z') + || ('A' <= self && self <= 'Z') + || ('0' <= self && self <= '9') + || self == '_' + || (self > '\x7f' && derived_property::XID_Continue(self)) } } |