authorgravatar for dec05eba@protonmail.comdec05eba <dec05eba@protonmail.com> 2020-09-05 14:52:16+02:00
committergravatar for dec05eba@protonmail.comdec05eba <dec05eba@protonmail.com> 2020-09-05 14:56:59+02:00
logdb51821a97bfa18ad897713087e3e59b14ae4b21
tree78a7fd9a99a22b15cbca00eca0b3c823988a5b58
parent997451da03f25de310fc9f19393b19fbb5ac0062

Remove type size check, looks like its not needed

Add check if the type is float. Float byte comparison doesn't work because +0.0 and -0.0 are considered equal but their byte representations are not equal.

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

lib/std/mem.zig+6-2
......@@ -897,7 +897,9 @@ 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 if (!isValidAlign(T.bit_count) or haystack.len < 32 or needle.len <= 2)
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)
901903 return lastIndexOfLinear(T, haystack, needle);
902904
903905 const haystack_bytes = sliceAsBytes(haystack);
......@@ -921,7 +923,9 @@ pub fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?us
921923pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {
922924 if (needle.len > haystack.len or needle.len == 0) return null;
923925
924 if (!isValidAlign(T.bit_count) or haystack.len < 32 or needle.len <= 2)
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)
925929 return indexOfPosLinear(T, haystack, start_index, needle);
926930
927931 const haystack_bytes = sliceAsBytes(haystack);