aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Page <epage@duosecurity.com>2021-04-28 10:01:26 -0500
committerEd Page <epage@duosecurity.com>2021-04-28 10:01:30 -0500
commit122b38775cf077570025c8294280f57d2004096f (patch)
tree83c739b580ac61f3e25c24233405ed780412130b
parent4c762c188a111d8dfa79c4770a06b20236db280f (diff)
downloadunicode-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.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 01c81e2..af7015e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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))
}
}