From 122b38775cf077570025c8294280f57d2004096f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 28 Apr 2021 10:01:26 -0500 Subject: [PATCH] Add ASCII fast path from rust-lang See rust-lang/rust's `src/librustc_lexer/src/lib.rs` Idea came from #13 --- src/lib.rs | 12 ++++++++++-- 1 file 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)) } }