zig

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

commit 4db5bc7b2132d8794d98077a67fc410be9dc98bd (tree)
parent c911de825b3b9932e84345f6cec910553b21e203
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Thu, 23 Feb 2023 16:18:15 -0700

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

Diffstat:
Mlib/std/mem.zig | 13++++---------
1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/lib/std/mem.zig b/lib/std/mem.zig @@ -196,13 +196,8 @@ test "Allocator.resize" { /// dest.len must be >= source.len. /// If the slices overlap, dest.ptr must be <= src.ptr. pub fn copy(comptime T: type, dest: []T, source: []const T) void { - // TODO instead of manually doing this check for the whole array - // and turning off runtime safety, the compiler should detect loops like - // this and automatically omit safety checks for loops - @setRuntimeSafety(false); - assert(dest.len >= source.len); - for (source, 0..) |s, i| - dest[i] = s; + for (dest[0..source.len], source) |*d, s| + d.* = s; } /// Copy all of source into dest at position 0. @@ -611,8 +606,8 @@ test "lessThan" { pub fn eql(comptime T: type, a: []const T, b: []const T) bool { if (a.len != b.len) return false; if (a.ptr == b.ptr) return true; - for (a, 0..) |item, index| { - if (b[index] != item) return false; + for (a, b) |a_elem, b_elem| { + if (a_elem != b_elem) return false; } return true; }