authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-11-01 18:26:04+01:00
committergravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-12-09 21:57:17+01:00
log0162a0868c18dc94f8d89c0c95bd89ebd63c0b41
treee7aebbb1833c0792e66f06042c28372c72084272
parent19dbc5805c440dbfb22bbd3e75c7ec706655bb19

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 files changed, 2 insertions(+), 2 deletions(-)

lib/std/ascii.zig+2-2
...@@ -91,7 +91,7 @@ pub const control_code = struct {...@@ -91,7 +91,7 @@ pub const control_code = struct {
91/// Returns whether the character is alphanumeric: A-Z, a-z, or 0-9.91/// Returns whether the character is alphanumeric: A-Z, a-z, or 0-9.
92pub fn isAlphanumeric(c: u8) bool {92pub fn isAlphanumeric(c: u8) bool {
93 return switch (c) {93 return switch (c) {
94 'A'...'Z', 'a'...'z', '0'...'9' => true,94 '0'...'9', 'A'...'Z', 'a'...'z' => true,
95 else => false,95 else => false,
96 };96 };
97}97}
...@@ -167,7 +167,7 @@ pub fn isUpper(c: u8) bool {...@@ -167,7 +167,7 @@ pub fn isUpper(c: u8) bool {
167/// Returns whether the character is a hexadecimal digit: A-F, a-f, or 0-9.167/// Returns whether the character is a hexadecimal digit: A-F, a-f, or 0-9.
168pub fn isHex(c: u8) bool {168pub fn isHex(c: u8) bool {
169 return switch (c) {169 return switch (c) {
170 'A'...'F', 'a'...'f', '0'...'9' => true,170 '0'...'9', 'A'...'F', 'a'...'f' => true,
171 else => false,171 else => false,
172 };172 };
173}173}