mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
std.mem: add missing check to lastIndexOfLinear
This commit is contained in:
parent
c0448a6c7c
commit
6fa7d5d4ad
@ -1396,6 +1396,7 @@ pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) ?usize
|
||||
/// Consider using `lastIndexOf` instead of this, which will automatically use a
|
||||
/// more sophisticated algorithm on larger inputs.
|
||||
pub fn lastIndexOfLinear(comptime T: type, haystack: []const T, needle: []const T) ?usize {
|
||||
if (needle.len > haystack.len) return null;
|
||||
var i: usize = haystack.len - needle.len;
|
||||
while (true) : (i -= 1) {
|
||||
if (mem.eql(T, haystack[i..][0..needle.len], needle)) return i;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user