authorgravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2022-02-04 23:42:10-07:00
committergravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2022-05-11 18:41:23-06:00
log71f69190ef7a79650647cf5422633813756fbe48
treebf821e89d7bf7e1da1e6217f91e5e9ffdc085dcf
parent1c874a871fe4795f71edf6e9739b72d071eb453a

some fixes to the EnvMap HashContext


2 files changed, 10 insertions(+), 8 deletions(-)

lib/std/build/RunStep.zig+1-1
...@@ -99,7 +99,7 @@ pub fn clearEnvironment(self: *RunStep) void {...@@ -99,7 +99,7 @@ pub fn clearEnvironment(self: *RunStep) void {
99pub fn addPathDir(self: *RunStep, search_path: []const u8) void {99pub fn addPathDir(self: *RunStep, search_path: []const u8) void {
100 const env_map = self.getEnvMap();100 const env_map = self.getEnvMap();
101101
102 var key: []const u8 = "PATH";102 const key = "PATH";
103 var prev_path = env_map.get(key);103 var prev_path = env_map.get(key);
104104
105 if (prev_path) |pp| {105 if (prev_path) |pp| {
lib/std/process.zig+9-7
...@@ -62,18 +62,20 @@ pub const EnvMap = struct {...@@ -62,18 +62,20 @@ pub const EnvMap = struct {
62 std.hash_map.default_max_load_percentage,62 std.hash_map.default_max_load_percentage,
63 );63 );
6464
65 pub const Size = HashMap.Size;
66
65 pub const EnvNameHashContext = struct {67 pub const EnvNameHashContext = struct {
66 fn upcase(c: u21) u21 {68 fn upcase(c: u21) u21 {
67 if (c <= std.math.maxInt(u16))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 return c;71 return c;
70 }72 }
7173
72 pub fn hash(self: @This(), s: []const u8) u64 {74 pub fn hash(self: @This(), s: []const u8) u64 {
73 _ = self;75 _ = self;
74 if (builtin.os.tag == .windows) {76 if (builtin.os.tag == .windows) {
75 const h = std.hash.Wyhash.init(0);77 var h = std.hash.Wyhash.init(0);
76 var it = std.unicode.Utf8View(s).iterator();78 var it = std.unicode.Utf8View.initUnchecked(s).iterator();
77 while (it.nextCodepoint()) |cp| {79 while (it.nextCodepoint()) |cp| {
78 const cp_upper = upcase(cp);80 const cp_upper = upcase(cp);
79 h.update(&[_]u8{81 h.update(&[_]u8{
...@@ -90,15 +92,15 @@ pub const EnvMap = struct {...@@ -90,15 +92,15 @@ pub const EnvMap = struct {
90 pub fn eql(self: @This(), a: []const u8, b: []const u8) bool {92 pub fn eql(self: @This(), a: []const u8, b: []const u8) bool {
91 _ = self;93 _ = self;
92 if (builtin.os.tag == .windows) {94 if (builtin.os.tag == .windows) {
93 var it_a = std.unicode.Utf8View(a).iterator();95 var it_a = std.unicode.Utf8View.initUnchecked(a).iterator();
94 var it_b = std.unicode.Utf8View(b).iterator();96 var it_b = std.unicode.Utf8View.initUnchecked(b).iterator();
95 while (true) {97 while (true) {
96 const c_a = it_a.nextCodepoint() orelse break;98 const c_a = it_a.nextCodepoint() orelse break;
97 const c_b = it_b.nextCodepoint() orelse return false;99 const c_b = it_b.nextCodepoint() orelse return false;
98 if (upcase(c_a) != upcase(c_b))100 if (upcase(c_a) != upcase(c_b))
99 return false;101 return false;
100 }102 }
101 if (it_b.nextCodepoint()) return false;103 if (it_b.nextCodepoint()) |_| return false;
102 }104 }
103 return std.hash_map.eqlString(a, b);105 return std.hash_map.eqlString(a, b);
104 }106 }
...@@ -220,7 +222,7 @@ test "EnvMap" {...@@ -220,7 +222,7 @@ test "EnvMap" {
220 var it = env.iterator();222 var it = env.iterator();
221 var count: EnvMap.Size = 0;223 var count: EnvMap.Size = 0;
222 while (it.next()) |entry| {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 try testing.expect(is_an_expected_name);226 try testing.expect(is_an_expected_name);
225 count += 1;227 count += 1;
226 }228 }