authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-02-23 16:18:15-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:12-07:00
log4db5bc7b2132d8794d98077a67fc410be9dc98bd
tree8fc68ee9bf86542f804aaf9f4208a32d7eab9e95
parentc911de825b3b9932e84345f6cec910553b21e203

std.mem.copy: update to new for loop syntax


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

lib/std/mem.zig+4-9
......@@ -196,13 +196,8 @@ test "Allocator.resize" {
196196/// dest.len must be >= source.len.
197197/// If the slices overlap, dest.ptr must be <= src.ptr.
198198pub fn copy(comptime T: type, dest: []T, source: []const T) void {
199 // TODO instead of manually doing this check for the whole array
200 // and turning off runtime safety, the compiler should detect loops like
201 // this and automatically omit safety checks for loops
202 @setRuntimeSafety(false);
203 assert(dest.len >= source.len);
204 for (source, 0..) |s, i|
205 dest[i] = s;
199 for (dest[0..source.len], source) |*d, s|
200 d.* = s;
206201}
207202
208203/// Copy all of source into dest at position 0.
......@@ -611,8 +606,8 @@ test "lessThan" {
611606pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
612607 if (a.len != b.len) return false;
613608 if (a.ptr == b.ptr) return true;
614 for (a, 0..) |item, index| {
615 if (b[index] != item) return false;
609 for (a, b) |a_elem, b_elem| {
610 if (a_elem != b_elem) return false;
616611 }
617612 return true;
618613}