zig

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

commit 6ebeb85abdca74c70d59b5f4f5ceea0acd77a108 (tree)
parent d525c598081ef2e6639135e9375f50199d74f726
Author: xdBronch <51252236+xdBronch@users.noreply.github.com>
Date:   Sun, 10 Dec 2023 13:56:39 -0500

speed up sliceTo when end == sentinel

Diffstat:
Mlib/std/mem.zig | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/std/mem.zig b/lib/std/mem.zig @@ -861,7 +861,10 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize { }, .Many => if (ptr_info.sentinel) |sentinel_ptr| { const sentinel = @as(*align(1) const ptr_info.child, @ptrCast(sentinel_ptr)).*; - // We may be looking for something other than the sentinel, + if (sentinel == end) { + return indexOfSentinel(ptr_info.child, end, ptr); + } + // We're looking for something other than the sentinel, // but iterating past the sentinel would be a bug so we need // to check for both. var i: usize = 0;