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" {...@@ -196,13 +196,8 @@ test "Allocator.resize" {
196/// dest.len must be >= source.len.196/// dest.len must be >= source.len.
197/// If the slices overlap, dest.ptr must be <= src.ptr.197/// If the slices overlap, dest.ptr must be <= src.ptr.
198pub fn copy(comptime T: type, dest: []T, source: []const T) void {198pub fn copy(comptime T: type, dest: []T, source: []const T) void {
199 // TODO instead of manually doing this check for the whole array199 for (dest[0..source.len], source) |*d, s|
200 // and turning off runtime safety, the compiler should detect loops like200 d.* = s;
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;
206}201}
207202
208/// Copy all of source into dest at position 0.203/// Copy all of source into dest at position 0.
...@@ -611,8 +606,8 @@ test "lessThan" {...@@ -611,8 +606,8 @@ test "lessThan" {
611pub fn eql(comptime T: type, a: []const T, b: []const T) bool {606pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
612 if (a.len != b.len) return false;607 if (a.len != b.len) return false;
613 if (a.ptr == b.ptr) return true;608 if (a.ptr == b.ptr) return true;
614 for (a, 0..) |item, index| {609 for (a, b) |a_elem, b_elem| {
615 if (b[index] != item) return false;610 if (a_elem != b_elem) return false;
616 }611 }
617 return true;612 return true;
618}613}