| ... | ... | @@ -62,18 +62,20 @@ pub const EnvMap = struct { |
| 62 | 62 | std.hash_map.default_max_load_percentage, |
| 63 | 63 | ); |
| 64 | 64 | |
| 65 | pub const Size = HashMap.Size; |
| 66 | |
| 65 | 67 | pub const EnvNameHashContext = struct { |
| 66 | 68 | fn upcase(c: u21) u21 { |
| 67 | 69 | if (c <= std.math.maxInt(u16)) |
| 68 | | return std.os.windows.ntdll.RtlUpcaseUnicodeChar(c); |
| 70 | return std.os.windows.ntdll.RtlUpcaseUnicodeChar(@intCast(u16, c)); |
| 69 | 71 | return c; |
| 70 | 72 | } |
| 71 | 73 | |
| 72 | 74 | pub fn hash(self: @This(), s: []const u8) u64 { |
| 73 | 75 | _ = self; |
| 74 | 76 | if (builtin.os.tag == .windows) { |
| 75 | | const h = std.hash.Wyhash.init(0); |
| 76 | | var it = std.unicode.Utf8View(s).iterator(); |
| 77 | var h = std.hash.Wyhash.init(0); |
| 78 | var it = std.unicode.Utf8View.initUnchecked(s).iterator(); |
| 77 | 79 | while (it.nextCodepoint()) |cp| { |
| 78 | 80 | const cp_upper = upcase(cp); |
| 79 | 81 | h.update(&[_]u8{ |
| ... | ... | @@ -90,15 +92,15 @@ pub const EnvMap = struct { |
| 90 | 92 | pub fn eql(self: @This(), a: []const u8, b: []const u8) bool { |
| 91 | 93 | _ = self; |
| 92 | 94 | if (builtin.os.tag == .windows) { |
| 93 | | var it_a = std.unicode.Utf8View(a).iterator(); |
| 94 | | var it_b = std.unicode.Utf8View(b).iterator(); |
| 95 | var it_a = std.unicode.Utf8View.initUnchecked(a).iterator(); |
| 96 | var it_b = std.unicode.Utf8View.initUnchecked(b).iterator(); |
| 95 | 97 | while (true) { |
| 96 | 98 | const c_a = it_a.nextCodepoint() orelse break; |
| 97 | 99 | const c_b = it_b.nextCodepoint() orelse return false; |
| 98 | 100 | if (upcase(c_a) != upcase(c_b)) |
| 99 | 101 | return false; |
| 100 | 102 | } |
| 101 | | if (it_b.nextCodepoint()) return false; |
| 103 | if (it_b.nextCodepoint()) |_| return false; |
| 102 | 104 | } |
| 103 | 105 | return std.hash_map.eqlString(a, b); |
| 104 | 106 | } |
| ... | ... | @@ -220,7 +222,7 @@ test "EnvMap" { |
| 220 | 222 | var it = env.iterator(); |
| 221 | 223 | var count: EnvMap.Size = 0; |
| 222 | 224 | while (it.next()) |entry| { |
| 223 | | const is_an_expected_name = std.mem.eql(u8, "SOMETHING_NEW", entry.name) or std.mem.eql(u8, "SOMETHING_NEW_AND_LONGER", entry.name); |
| 225 | const is_an_expected_name = std.mem.eql(u8, "SOMETHING_NEW", entry.key_ptr.*) or std.mem.eql(u8, "SOMETHING_NEW_AND_LONGER", entry.key_ptr.*); |
| 224 | 226 | try testing.expect(is_an_expected_name); |
| 225 | 227 | count += 1; |
| 226 | 228 | } |