authorgravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2026-05-08 22:04:30+01:00
committergravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2026-05-08 22:04:30+01:00
log33d2e571c763ca1f0d2d97803ece92b49a54aac5
tree2f30aa08cc805242faabb099bb4ddd1910cb9615
parent83da6827fdda6f0304228bba3e78e8624c4540ee

std.mem: Remove containsAtLeastScalar() in favor of new impl


2 files changed, 10 insertions(+), 15 deletions(-)

lib/std/Io/Threaded.zig+1-1
...@@ -14401,7 +14401,7 @@ pub fn setTimestampToPosix(set_ts: File.SetTimestamp) posix.timespec {...@@ -14401,7 +14401,7 @@ pub fn setTimestampToPosix(set_ts: File.SetTimestamp) posix.timespec {
14401}14401}
1440214402
14403pub fn pathToPosix(file_path: []const u8, buffer: *[posix.PATH_MAX]u8) Dir.PathNameError![:0]u8 {14403pub fn pathToPosix(file_path: []const u8, buffer: *[posix.PATH_MAX]u8) Dir.PathNameError![:0]u8 {
14404 if (std.mem.containsAtLeastScalar2(u8, file_path, 0, 1)) return error.BadPathName;14404 if (std.mem.containsAtLeastScalar(u8, file_path, 0, 1)) return error.BadPathName;
14405 // >= rather than > to make room for the null byte14405 // >= rather than > to make room for the null byte
14406 if (file_path.len >= buffer.len) return error.NameTooLong;14406 if (file_path.len >= buffer.len) return error.NameTooLong;
14407 @memcpy(buffer[0..file_path.len], file_path);14407 @memcpy(buffer[0..file_path.len], file_path);
lib/std/mem.zig+9-14
...@@ -1691,7 +1691,7 @@ test countScalar {...@@ -1691,7 +1691,7 @@ test countScalar {
1691//1691//
1692/// See also: `containsAtLeastScalar`1692/// See also: `containsAtLeastScalar`
1693pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: usize, needle: []const T) bool {1693pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: usize, needle: []const T) bool {
1694 if (needle.len == 1) return containsAtLeastScalar(T, haystack, expected_count, needle[0]);1694 if (needle.len == 1) return containsAtLeastScalar(T, haystack, needle[0], expected_count);
1695 assert(needle.len > 0);1695 assert(needle.len > 0);
1696 if (expected_count == 0) return true;1696 if (expected_count == 0) return true;
16971697
...@@ -1722,17 +1722,12 @@ test containsAtLeast {...@@ -1722,17 +1722,12 @@ test containsAtLeast {
1722 try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));1722 try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));
1723}1723}
17241724
1725/// Deprecated in favor of `containsAtLeastScalar2`.
1726pub fn containsAtLeastScalar(comptime T: type, list: []const T, minimum: usize, element: T) bool {
1727 return containsAtLeastScalar2(T, list, element, minimum);
1728}
1729
1730/// Returns true if `element` appears at least `minimum` number of times in `list`.1725/// Returns true if `element` appears at least `minimum` number of times in `list`.
1731//1726//
1732/// Related:1727/// Related:
1733/// * `containsAtLeast`1728/// * `containsAtLeast`
1734/// * `countScalar`1729/// * `countScalar`
1735pub fn containsAtLeastScalar2(comptime T: type, list: []const T, element: T, minimum: usize) bool {1730pub fn containsAtLeastScalar(comptime T: type, list: []const T, element: T, minimum: usize) bool {
1736 const n = list.len;1731 const n = list.len;
1737 var i: usize = 0;1732 var i: usize = 0;
1738 var found: usize = 0;1733 var found: usize = 0;
...@@ -1760,14 +1755,14 @@ pub fn containsAtLeastScalar2(comptime T: type, list: []const T, element: T, min...@@ -1760,14 +1755,14 @@ pub fn containsAtLeastScalar2(comptime T: type, list: []const T, element: T, min
1760 return false;1755 return false;
1761}1756}
17621757
1763test containsAtLeastScalar2 {1758test containsAtLeastScalar {
1764 try testing.expect(containsAtLeastScalar2(u8, "aa", 'a', 0));1759 try testing.expect(containsAtLeastScalar(u8, "aa", 'a', 0));
1765 try testing.expect(containsAtLeastScalar2(u8, "aa", 'a', 1));1760 try testing.expect(containsAtLeastScalar(u8, "aa", 'a', 1));
1766 try testing.expect(containsAtLeastScalar2(u8, "aa", 'a', 2));1761 try testing.expect(containsAtLeastScalar(u8, "aa", 'a', 2));
1767 try testing.expect(!containsAtLeastScalar2(u8, "aa", 'a', 3));1762 try testing.expect(!containsAtLeastScalar(u8, "aa", 'a', 3));
17681763
1769 try testing.expect(containsAtLeastScalar2(u8, "adadda", 'd', 3));1764 try testing.expect(containsAtLeastScalar(u8, "adadda", 'd', 3));
1770 try testing.expect(!containsAtLeastScalar2(u8, "adadda", 'd', 4));1765 try testing.expect(!containsAtLeastScalar(u8, "adadda", 'd', 4));
1771}1766}
17721767
1773/// Reads an integer from memory with size equal to bytes.len.1768/// Reads an integer from memory with size equal to bytes.len.