zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 33d2e571c763ca1f0d2d97803ece92b49a54aac5 (tree)
parent 83da6827fdda6f0304228bba3e78e8624c4540ee
Author: Linus Groh <mail@linusgroh.de>
Date:   Fri,  8 May 2026 22:04:30 +0100

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

Diffstat:
Mlib/std/Io/Threaded.zig | 2+-
Mlib/std/mem.zig | 23+++++++++--------------
2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig @@ -14401,7 +14401,7 @@ pub fn setTimestampToPosix(set_ts: File.SetTimestamp) posix.timespec { } pub fn pathToPosix(file_path: []const u8, buffer: *[posix.PATH_MAX]u8) Dir.PathNameError![:0]u8 { - if (std.mem.containsAtLeastScalar2(u8, file_path, 0, 1)) return error.BadPathName; + if (std.mem.containsAtLeastScalar(u8, file_path, 0, 1)) return error.BadPathName; // >= rather than > to make room for the null byte if (file_path.len >= buffer.len) return error.NameTooLong; @memcpy(buffer[0..file_path.len], file_path); diff --git a/lib/std/mem.zig b/lib/std/mem.zig @@ -1691,7 +1691,7 @@ test countScalar { // /// See also: `containsAtLeastScalar` pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: usize, needle: []const T) bool { - if (needle.len == 1) return containsAtLeastScalar(T, haystack, expected_count, needle[0]); + if (needle.len == 1) return containsAtLeastScalar(T, haystack, needle[0], expected_count); assert(needle.len > 0); if (expected_count == 0) return true; @@ -1722,17 +1722,12 @@ test containsAtLeast { try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar")); } -/// Deprecated in favor of `containsAtLeastScalar2`. -pub fn containsAtLeastScalar(comptime T: type, list: []const T, minimum: usize, element: T) bool { - return containsAtLeastScalar2(T, list, element, minimum); -} - /// Returns true if `element` appears at least `minimum` number of times in `list`. // /// Related: /// * `containsAtLeast` /// * `countScalar` -pub fn containsAtLeastScalar2(comptime T: type, list: []const T, element: T, minimum: usize) bool { +pub fn containsAtLeastScalar(comptime T: type, list: []const T, element: T, minimum: usize) bool { const n = list.len; var i: usize = 0; var found: usize = 0; @@ -1760,14 +1755,14 @@ pub fn containsAtLeastScalar2(comptime T: type, list: []const T, element: T, min return false; } -test containsAtLeastScalar2 { - try testing.expect(containsAtLeastScalar2(u8, "aa", 'a', 0)); - try testing.expect(containsAtLeastScalar2(u8, "aa", 'a', 1)); - try testing.expect(containsAtLeastScalar2(u8, "aa", 'a', 2)); - try testing.expect(!containsAtLeastScalar2(u8, "aa", 'a', 3)); +test containsAtLeastScalar { + try testing.expect(containsAtLeastScalar(u8, "aa", 'a', 0)); + try testing.expect(containsAtLeastScalar(u8, "aa", 'a', 1)); + try testing.expect(containsAtLeastScalar(u8, "aa", 'a', 2)); + try testing.expect(!containsAtLeastScalar(u8, "aa", 'a', 3)); - try testing.expect(containsAtLeastScalar2(u8, "adadda", 'd', 3)); - try testing.expect(!containsAtLeastScalar2(u8, "adadda", 'd', 4)); + try testing.expect(containsAtLeastScalar(u8, "adadda", 'd', 3)); + try testing.expect(!containsAtLeastScalar(u8, "adadda", 'd', 4)); } /// Reads an integer from memory with size equal to bytes.len.