File tree 1 file changed +19
-2
lines changed
1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -128,8 +128,25 @@ pub struct ByteSerialize<'a> {
128
128
bytes : & ' a [ u8 ] ,
129
129
}
130
130
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
+ #[ inline]
145
+ pub fn byte_serialized_unchanged ( byte : u8 ) -> bool {
146
+ if byte > b'z' {
147
+ return false ;
148
+ }
149
+ ( ( MAGIC >> byte) & 1 ) == 1
133
150
}
134
151
135
152
impl < ' a > Iterator for ByteSerialize < ' a > {
You can’t perform that action at this time.
0 commit comments