From 83b6383ab486aca7ee3c53adad63f1707340b259 Mon Sep 17 00:00:00 2001 From: Ryan Sepassi Date: Tue, 22 Aug 2023 17:01:40 -0700 Subject: [PATCH] tweak comptime lookup table --- ulid.zig | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/ulid.zig b/ulid.zig index a33d252..2211400 100644 --- a/ulid.zig +++ b/ulid.zig @@ -13,8 +13,8 @@ const text_rand_bytes = 16; fn alphaIdx(c: u8) ?u8 { const alpha_idxs = comptime blk: { - var idxs = [1]?u8{null} ** 256; - for (0..256) |i| idxs[i] = _alphaIdx(@truncate(i)); + var idxs: [256]?u8 = undefined; + for (0..256) |i| idxs[i] = _alphaIdx(i); break :blk idxs; }; return alpha_idxs[c]; @@ -22,20 +22,19 @@ fn alphaIdx(c: u8) ?u8 { fn _alphaIdx(c: u8) ?u8 { return switch (c) { - // inline 0...47 => null, + inline 0...47 => null, inline '0'...'9' => |i| i - 48, - // inline 58...64 => null, + inline 58...64 => null, inline 'A'...'H' => |i| i - 65 + 10, - // inline 'I' => null, + inline 'I' => null, inline 'J'...'K' => |i| i - 65 + 10 - 1, - // inline 'L' => null, + inline 'L' => null, inline 'M'...'N' => |i| i - 65 + 10 - 2, - // inline 'O' => null, + inline 'O' => null, inline 'P'...'T' => |i| i - 65 + 10 - 3, - // inline 'U' => null, + inline 'U' => null, inline 'V'...'Z' => |i| i - 65 + 10 - 4, - // inline 91...255 => null, - inline else => null, + inline 91...255 => null, }; }