@@ -163,29 +163,29 @@ impl<'a> Lexer<'a> {
163
163
}
164
164
165
165
fn hex_digit ( & mut self ) -> Option < u32 > {
166
+ let b = self . peek_byte ( ) ?;
167
+
166
168
// Reduce instructions and remove 1 branch by comparing against `A-F` and `a-f` simultaneously
167
169
// https://godbolt.org/z/9caMMzvP3
168
- let value = if let Some ( b) = self . peek_byte ( ) {
169
- if b. is_ascii_digit ( ) {
170
- b - b'0'
170
+ let value = if b. is_ascii_digit ( ) {
171
+ b - b'0'
172
+ } else {
173
+ // Match `A-F` or `a-f`. `b | 32` converts uppercase letters to lowercase,
174
+ // but leaves lowercase as they are
175
+ let lower_case = b | 32 ;
176
+ if matches ! ( lower_case, b'a' ..=b'f' ) {
177
+ lower_case + 10 - b'a'
171
178
} else {
172
- // Match `A-F` or `a-f`. `b | 32` converts uppercase letters to lowercase,
173
- // but leaves lowercase as they are
174
- let lower_case = b | 32 ;
175
- if matches ! ( lower_case, b'a' ..=b'f' ) {
176
- lower_case + 10 - b'a'
177
- } else {
178
- return None ;
179
- }
179
+ return None ;
180
180
}
181
- } else {
182
- return None ;
183
181
} ;
182
+
184
183
// Because of `b | 32` above, compiler cannot deduce that next byte is definitely ASCII
185
184
// so `next_byte_unchecked` is necessary to produce compact assembly, rather than `consume_char`.
186
185
// SAFETY: This code is only reachable if there is a byte remaining, and it's ASCII.
187
186
// Therefore it's safe to consume that byte, and will leave position on a UTF-8 char boundary.
188
187
unsafe { self . source . next_byte_unchecked ( ) } ;
188
+
189
189
Some ( u32:: from ( value) )
190
190
}
191
191
0 commit comments