authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-11 22:18:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-02-23 02:37:10-07:00
log06d0c58305a04d28da9a2caf510fc906e38a54ef
tree4dfe2c67f9a443dba7e4c5453f187d5edc217811
parentb47bd031ca0b8c3a14c0dd6537e13e60779471a4

std.mem: take advantage of length-based slicing


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

lib/std/mem.zig+2-2
...@@ -1338,7 +1338,7 @@ pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) ?usize...@@ -1338,7 +1338,7 @@ pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) ?usize
1338pub fn lastIndexOfLinear(comptime T: type, haystack: []const T, needle: []const T) ?usize {1338pub fn lastIndexOfLinear(comptime T: type, haystack: []const T, needle: []const T) ?usize {
1339 var i: usize = haystack.len - needle.len;1339 var i: usize = haystack.len - needle.len;
1340 while (true) : (i -= 1) {1340 while (true) : (i -= 1) {
1341 if (mem.eql(T, haystack[i .. i + needle.len], needle)) return i;1341 if (mem.eql(T, haystack[i..][0..needle.len], needle)) return i;
1342 if (i == 0) return null;1342 if (i == 0) return null;
1343 }1343 }
1344}1344}
...@@ -1349,7 +1349,7 @@ pub fn indexOfPosLinear(comptime T: type, haystack: []const T, start_index: usiz...@@ -1349,7 +1349,7 @@ pub fn indexOfPosLinear(comptime T: type, haystack: []const T, start_index: usiz
1349 var i: usize = start_index;1349 var i: usize = start_index;
1350 const end = haystack.len - needle.len;1350 const end = haystack.len - needle.len;
1351 while (i <= end) : (i += 1) {1351 while (i <= end) : (i += 1) {
1352 if (eql(T, haystack[i .. i + needle.len], needle)) return i;1352 if (eql(T, haystack[i..][0..needle.len], needle)) return i;
1353 }1353 }
1354 return null;1354 return null;
1355}1355}