We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 84cf467 commit c98773fCopy full SHA for c98773f
form_urlencoded/src/lib.rs
@@ -128,8 +128,25 @@ pub struct ByteSerialize<'a> {
128
bytes: &'a [u8],
129
}
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')
+/// This is a precomputed table of which chars match and which don't.
+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
150
151
152
impl<'a> Iterator for ByteSerialize<'a> {
0 commit comments