mirror of
https://github.com/ziglang/zig.git
synced 2025-12-24 15:13:08 +00:00
std.mem: take advantage of length-based slicing
This commit is contained in:
parent
b47bd031ca
commit
06d0c58305
@ -1338,7 +1338,7 @@ pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) ?usize
|
||||
pub fn lastIndexOfLinear(comptime T: type, haystack: []const T, needle: []const T) ?usize {
|
||||
var i: usize = haystack.len - needle.len;
|
||||
while (true) : (i -= 1) {
|
||||
if (mem.eql(T, haystack[i .. i + needle.len], needle)) return i;
|
||||
if (mem.eql(T, haystack[i..][0..needle.len], needle)) return i;
|
||||
if (i == 0) return null;
|
||||
}
|
||||
}
|
||||
@ -1349,7 +1349,7 @@ pub fn indexOfPosLinear(comptime T: type, haystack: []const T, start_index: usiz
|
||||
var i: usize = start_index;
|
||||
const end = haystack.len - needle.len;
|
||||
while (i <= end) : (i += 1) {
|
||||
if (eql(T, haystack[i .. i + needle.len], needle)) return i;
|
||||
if (eql(T, haystack[i..][0..needle.len], needle)) return i;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user