authorgravatar for dec05eba@protonmail.comdec05eba <dec05eba@protonmail.com> 2020-09-05 15:20:48+02:00
committergravatar for dec05eba@protonmail.comdec05eba <dec05eba@protonmail.com> 2020-09-05 15:20:48+02:00
log3a6e6bd538858d2aa271b8975a6e1f742fec144f
tree54cb555d2bcb7793d1728ae760acaad4baad8df6
parentdb51821a97bfa18ad897713087e3e59b14ae4b21

Check if the type has unique bit representation to see if it can be compared byte-wise


1 files changed, 2 insertions(+), 6 deletions(-)

lib/std/mem.zig+2-6
......@@ -897,9 +897,7 @@ fn boyerMooreHorspoolPreprocess(pattern: []const u8, table: *[256]usize) void {
897897pub fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?usize {
898898 if (needle.len > haystack.len or needle.len == 0) return null;
899899
900 // byte comparison with float doesn't work because +0.0 and -0.0 and considered
901 // equal but their byte representations are not equal.
902 if (@typeInfo(T) == .Float or haystack.len < 32 or needle.len <= 2)
900 if (!meta.trait.hasUniqueRepresentation(T) or haystack.len < 32 or needle.len <= 2)
903901 return lastIndexOfLinear(T, haystack, needle);
904902
905903 const haystack_bytes = sliceAsBytes(haystack);
......@@ -923,9 +921,7 @@ pub fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?us
923921pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {
924922 if (needle.len > haystack.len or needle.len == 0) return null;
925923
926 // byte comparison with float doesn't work because +0.0 and -0.0 and considered
927 // equal but their byte representations are not equal.
928 if (@typeInfo(T) == .Float or haystack.len < 32 or needle.len <= 2)
924 if (!meta.trait.hasUniqueRepresentation(T) or haystack.len < 32 or needle.len <= 2)
929925 return indexOfPosLinear(T, haystack, start_index, needle);
930926
931927 const haystack_bytes = sliceAsBytes(haystack);