Skip to content

Commit 2015ec9

Browse files
committed
isHex, isAlphanumeric: prong reorder
On x86 interestingly I can see a reduction in codesize by 1 instruction with this. While not necessarily faster, it might still reduce codesize a bit and this ordering is also more logical because it follows ASCII table order. Rust's std uses this ordering too. See https://zig.godbolt.org/z/PqodY8YqY for the difference.
1 parent 6f8e8e0 commit 2015ec9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/std/ascii.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub const control_code = struct {
9191
/// Returns whether the character is alphanumeric: A-Z, a-z, or 0-9.
9292
pub fn isAlphanumeric(c: u8) bool {
9393
return switch (c) {
94-
'A'...'Z', 'a'...'z', '0'...'9' => true,
94+
'0'...'9', 'A'...'Z', 'a'...'z' => true,
9595
else => false,
9696
};
9797
}
@@ -169,7 +169,7 @@ pub fn isUpper(c: u8) bool {
169169
/// Returns whether the character is a hexadecimal digit: A-F, a-f, or 0-9.
170170
pub fn isHex(c: u8) bool {
171171
return switch (c) {
172-
'A'...'F', 'a'...'f', '0'...'9' => true,
172+
'0'...'9', 'A'...'F', 'a'...'f' => true,
173173
else => false,
174174
};
175175
}

0 commit comments

Comments
 (0)