| ... | @@ -1344,7 +1344,11 @@ pub fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?us | ... | @@ -1344,7 +1344,11 @@ pub fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?us |
| 1344 | /// Uses Boyer-Moore-Horspool algorithm on large inputs; `indexOfPosLinear` on small inputs. | 1344 | /// Uses Boyer-Moore-Horspool algorithm on large inputs; `indexOfPosLinear` on small inputs. |
| 1345 | pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize { | 1345 | pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize { |
| 1346 | if (needle.len > haystack.len) return null; | 1346 | if (needle.len > haystack.len) return null; |
| 1347 | if (needle.len == 0) return start_index; | 1347 | if (needle.len < 2) { |
| | 1348 | if (needle.len == 0) return start_index; |
| | 1349 | // indexOfScalarPos is significantly faster than indexOfPosLinear |
| | 1350 | return indexOfScalarPos(T, haystack, start_index, needle[0]); |
| | 1351 | } |
| 1348 | | 1352 | |
| 1349 | if (!meta.trait.hasUniqueRepresentation(T) or haystack.len < 52 or needle.len <= 4) | 1353 | if (!meta.trait.hasUniqueRepresentation(T) or haystack.len < 52 or needle.len <= 4) |
| 1350 | return indexOfPosLinear(T, haystack, start_index, needle); | 1354 | return indexOfPosLinear(T, haystack, start_index, needle); |