mirror of
https://github.com/ziglang/zig.git
synced 2026-01-04 20:43:19 +00:00
std: use simple eqlBytes for spirv
The SPIR-V backend doesn't support the advanced eqlBytes yet, and when it does, it likely that it will be detrimental.
This commit is contained in:
parent
a1b607acb5
commit
3ef5b80d2c
@ -632,10 +632,16 @@ test "lessThan" {
|
||||
try testing.expect(lessThan(u8, "", "a"));
|
||||
}
|
||||
|
||||
const backend_can_use_eql_bytes = switch (builtin.zig_backend) {
|
||||
// The SPIR-V backend does not support the optimized path yet.
|
||||
.stage2_spirv64 => false,
|
||||
else => true,
|
||||
};
|
||||
|
||||
/// Compares two slices and returns whether they are equal.
|
||||
pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
|
||||
if (@sizeOf(T) == 0) return true;
|
||||
if (!@inComptime() and std.meta.hasUniqueRepresentation(T)) return eqlBytes(sliceAsBytes(a), sliceAsBytes(b));
|
||||
if (!@inComptime() and std.meta.hasUniqueRepresentation(T) and backend_can_use_eql_bytes) return eqlBytes(sliceAsBytes(a), sliceAsBytes(b));
|
||||
|
||||
if (a.len != b.len) return false;
|
||||
if (a.len == 0 or a.ptr == b.ptr) return true;
|
||||
@ -648,6 +654,10 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
|
||||
|
||||
/// std.mem.eql heavily optimized for slices of bytes.
|
||||
fn eqlBytes(a: []const u8, b: []const u8) bool {
|
||||
if (!backend_can_use_eql_bytes) {
|
||||
return eql(u8, a, b);
|
||||
}
|
||||
|
||||
if (a.len != b.len) return false;
|
||||
if (a.len == 0 or a.ptr == b.ptr) return true;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user