File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -128,8 +128,24 @@ pub struct ByteSerialize<'a> {
128128 bytes : & ' a [ u8 ] ,
129129}
130130
131- fn byte_serialized_unchanged ( byte : u8 ) -> bool {
132- matches ! ( byte, b'*' | b'-' | b'.' | b'0' ..= b'9' | b'A' ..= b'Z' | b'_' | b'a' ..= b'z' )
131+ /// This is a precomputed table of which chars match and which don't.
132+ const MAGIC : u128 = const {
133+ let mut magic = 0_u128 ;
134+ let mut c = 0 ;
135+ while c < 128 {
136+ magic |= ( matches ! ( c, b'*' | b'-' | b'.' | b'0' ..= b'9' | b'A' ..= b'Z' | b'_' | b'a' ..= b'z' )
137+ as u128 )
138+ << c;
139+ c += 1 ;
140+ }
141+ magic
142+ } ;
143+
144+ pub fn byte_serialized_unchanged ( byte : u8 ) -> bool {
145+ if byte > b'z' {
146+ return false ;
147+ }
148+ ( ( MAGIC >> byte) & 1 ) == 1
133149}
134150
135151impl < ' a > Iterator for ByteSerialize < ' a > {
You can’t perform that action at this time.
0 commit comments