authorgravatar for dec05eba@protonmail.comdec05eba <dec05eba@protonmail.com> 2020-09-05 12:57:05+02:00
committergravatar for dec05eba@protonmail.comdec05eba <dec05eba@protonmail.com> 2020-09-05 12:57:05+02:00
logf65f3d24f8c6fcdc54da3a904999405508f0e706
tree5ffa51145713fe54fa9de6ad6fd40b0775a4c416
parentd012507a8fc911b662085a70bee2d580a404bb81

Only use boyer-moore-horsepool for types that are power of 2


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

lib/std/mem.zig+6-6
......@@ -888,13 +888,13 @@ fn boyerMooreHorspoolPreprocess(pattern: []const u8, table: []usize) void {
888888/// To start looking at a different index, slice the haystack first.
889889// Reverse boyer-moore-horspool algorithm
890890pub fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?usize {
891 if (haystack.len < 32 or needle.len <= 2)
891 if (!isValidAlign(T.bit_count) or haystack.len < 32 or needle.len <= 2)
892892 return lastIndexOfNaive(T, haystack, needle);
893893
894894 if (needle.len > haystack.len or needle.len == 0) return null;
895895
896 const haystackU8 = @bitCast([]const u8, haystack);
897 const needleU8 = @bitCast([]const u8, needle);
896 const haystackU8 = sliceAsBytes(haystack);
897 const needleU8 = sliceAsBytes(needle);
898898
899899 var table: [256]usize = undefined;
900900 boyerMooreHorspoolPreprocess(needleU8, table[0..]);
......@@ -911,13 +911,13 @@ pub fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?us
911911
912912// Boyer-moore-horspool algorithm
913913pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {
914 if (haystack.len < 32 or needle.len <= 2)
914 if (!isValidAlign(T.bit_count) or haystack.len < 32 or needle.len <= 2)
915915 return indexOfPosNaive(T, haystack, start_index, needle);
916916
917917 if (needle.len > haystack.len or needle.len == 0) return null;
918918
919 const haystackU8 = @bitCast([]const u8, haystack);
920 const needleU8 = @bitCast([]const u8, needle);
919 const haystackU8 = sliceAsBytes(haystack);
920 const needleU8 = sliceAsBytes(needle);
921921
922922 var table: [256]usize = undefined;
923923 boyerMooreHorspoolPreprocess(needleU8, table[0..]);