From 9d6f236728cf433b44048e21f81efdd167fe0098 Mon Sep 17 00:00:00 2001 From: Sahnvour Date: Tue, 3 Sep 2019 23:56:04 +0200 Subject: [PATCH] add fastpath for std.mem.eql and simplify std.hash_map.eqlString this should also be friendlier to the optimizer --- std/hash_map.zig | 4 +--- std/mem.zig | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/std/hash_map.zig b/std/hash_map.zig index 5a852d4302..4ffe88067b 100644 --- a/std/hash_map.zig +++ b/std/hash_map.zig @@ -23,9 +23,7 @@ pub fn StringHashMap(comptime V: type) type { } pub fn eqlString(a: []const u8, b: []const u8) bool { - if (a.len != b.len) return false; - if (a.ptr == b.ptr) return true; - return mem.compare(u8, a, b) == .Equal; + return mem.eql(u8, a, b); } pub fn hashString(s: []const u8) u32 { diff --git a/std/mem.zig b/std/mem.zig index 62a1ae886a..2091eb4804 100644 --- a/std/mem.zig +++ b/std/mem.zig @@ -339,6 +339,7 @@ test "mem.lessThan" { /// Compares two slices and returns whether they are equal. pub fn eql(comptime T: type, a: []const T, b: []const T) bool { if (a.len != b.len) return false; + if (a.ptr == b.ptr) return true; for (a) |item, index| { if (b[index] != item) return false; }