From c0fa5963ee692c9d4c46834978c274559d727ff5 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 24 Oct 2020 03:49:04 +0200 Subject: [PATCH] Make lastIndexOf use the same cut-off between BMH as indexOf Also update test to use a string longer than 52 characters to test both BMH and linear path. --- lib/std/mem.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/std/mem.zig b/lib/std/mem.zig index dd1c736626..862f064e55 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -907,7 +907,7 @@ pub fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?us if (needle.len > haystack.len) return null; if (needle.len == 0) return haystack.len; - if (!meta.trait.hasUniqueRepresentation(T) or haystack.len < 32 or needle.len <= 2) + if (!meta.trait.hasUniqueRepresentation(T) or haystack.len < 52 or needle.len <= 4) return lastIndexOfLinear(T, haystack, needle); const haystack_bytes = sliceAsBytes(haystack); @@ -951,10 +951,10 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee } test "mem.indexOf" { - testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "three four").? == 8); - testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "three four").? == 8); - testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "two two") == null); - testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "two two") == null); + testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8); + testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8); + testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null); + testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null); testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0); testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);