authorgravatar for 51252236+xdBronch@users.noreply.github.comxdBronch <51252236+xdBronch@users.noreply.github.com> 2023-12-10 13:56:39-05:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2024-01-04 17:54:56+02:00
log6ebeb85abdca74c70d59b5f4f5ceea0acd77a108
tree339440d03db33e27718197b587a756df7078ebab
parentd525c598081ef2e6639135e9375f50199d74f726

speed up sliceTo when end == sentinel


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

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