| ... | ... | @@ -632,10 +632,16 @@ test "lessThan" { |
| 632 | 632 | try testing.expect(lessThan(u8, "", "a")); |
| 633 | 633 | } |
| 634 | 634 | |
| 635 | const backend_can_use_eql_bytes = switch (builtin.zig_backend) { |
| 636 | // The SPIR-V backend does not support the optimized path yet. |
| 637 | .stage2_spirv64 => false, |
| 638 | else => true, |
| 639 | }; |
| 640 | |
| 635 | 641 | /// Compares two slices and returns whether they are equal. |
| 636 | 642 | pub fn eql(comptime T: type, a: []const T, b: []const T) bool { |
| 637 | 643 | if (@sizeOf(T) == 0) return true; |
| 638 | | if (!@inComptime() and std.meta.hasUniqueRepresentation(T)) return eqlBytes(sliceAsBytes(a), sliceAsBytes(b)); |
| 644 | if (!@inComptime() and std.meta.hasUniqueRepresentation(T) and backend_can_use_eql_bytes) return eqlBytes(sliceAsBytes(a), sliceAsBytes(b)); |
| 639 | 645 | |
| 640 | 646 | if (a.len != b.len) return false; |
| 641 | 647 | 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 { |
| 648 | 654 | |
| 649 | 655 | /// std.mem.eql heavily optimized for slices of bytes. |
| 650 | 656 | fn eqlBytes(a: []const u8, b: []const u8) bool { |
| 657 | if (!backend_can_use_eql_bytes) { |
| 658 | return eql(u8, a, b); |
| 659 | } |
| 660 | |
| 651 | 661 | if (a.len != b.len) return false; |
| 652 | 662 | if (a.len == 0 or a.ptr == b.ptr) return true; |
| 653 | 663 | |