mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
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.
This commit is contained in:
parent
72064eba23
commit
c0fa5963ee
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user