authorgravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2019-06-30 20:46:43+02:00
committergravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2019-08-04 12:34:05+02:00
logc9ce43f59fc777055612aeea58db0849390bc204
tree118bee2eb777d5e31d690baf9e9694b919442909
parent5bd407b27890fbed82891289e6a2bf2da93c2a41

fix hashmap using strings as keys


1 files changed, 11 insertions(+), 1 deletions(-)

std/http/headers.zig+11-1
...@@ -102,9 +102,19 @@ test "HeaderEntry" {...@@ -102,9 +102,19 @@ test "HeaderEntry" {
102 testing.expectEqualSlices(u8, "x", e.value);102 testing.expectEqualSlices(u8, "x", e.value);
103}103}
104104
105fn stringEql(a: []const u8, b: []const u8) bool {
106 if (a.len != b.len) return false;
107 if (a.ptr == b.ptr) return true;
108 return mem.compare(u8, a, b) == .Equal;
109}
110
111fn stringHash(s: []const u8) u32 {
112 return @truncate(u32, std.hash.wyhash(s, 0));
113}
114
105const HeaderList = std.ArrayList(HeaderEntry);115const HeaderList = std.ArrayList(HeaderEntry);
106const HeaderIndexList = std.ArrayList(usize);116const HeaderIndexList = std.ArrayList(usize);
107const HeaderIndex = std.AutoHashMap([]const u8, HeaderIndexList);117const HeaderIndex = std.HashMap([]const u8, HeaderIndexList, stringHash, stringEql);
108118
109pub const Headers = struct {119pub const Headers = struct {
110 // the owned header field name is stored in the index as part of the key120 // the owned header field name is stored in the index as part of the key