authorgravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2019-09-03 23:56:04+02:00
committergravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2019-09-03 23:56:04+02:00
log9d6f236728cf433b44048e21f81efdd167fe0098
treeb2c159f7032e470aa4cdaf9b24f096a8defd0dc2
parentf08c6e4fe6ad63145ef69377f36f34e9f04cadec

add fastpath for std.mem.eql and simplify std.hash_map.eqlString

this should also be friendlier to the optimizer

2 files changed, 2 insertions(+), 3 deletions(-)

std/hash_map.zig+1-3
...@@ -23,9 +23,7 @@ pub fn StringHashMap(comptime V: type) type {...@@ -23,9 +23,7 @@ pub fn StringHashMap(comptime V: type) type {
23}23}
2424
25pub fn eqlString(a: []const u8, b: []const u8) bool {25pub fn eqlString(a: []const u8, b: []const u8) bool {
26 if (a.len != b.len) return false;26 return mem.eql(u8, a, b);
27 if (a.ptr == b.ptr) return true;
28 return mem.compare(u8, a, b) == .Equal;
29}27}
3028
31pub fn hashString(s: []const u8) u32 {29pub fn hashString(s: []const u8) u32 {
std/mem.zig+1
...@@ -339,6 +339,7 @@ test "mem.lessThan" {...@@ -339,6 +339,7 @@ test "mem.lessThan" {
339/// Compares two slices and returns whether they are equal.339/// Compares two slices and returns whether they are equal.
340pub fn eql(comptime T: type, a: []const T, b: []const T) bool {340pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
341 if (a.len != b.len) return false;341 if (a.len != b.len) return false;
342 if (a.ptr == b.ptr) return true;
342 for (a) |item, index| {343 for (a) |item, index| {
343 if (b[index] != item) return false;344 if (b[index] != item) return false;
344 }345 }