mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
add fastpath for std.mem.eql and simplify std.hash_map.eqlString
this should also be friendlier to the optimizer
This commit is contained in:
parent
f08c6e4fe6
commit
9d6f236728
@ -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 {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user