| ... | @@ -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. |
| 198 | pub fn copy(comptime T: type, dest: []T, source: []const T) void { | 198 | pub fn copy(comptime T: type, dest: []T, source: []const T) void { |
| 199 | // TODO instead of manually doing this check for the whole array | 199 | for (dest[0..source.len], source) |*d, s| |
| 200 | // and turning off runtime safety, the compiler should detect loops like | 200 | 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 | } |
| 207 | | 202 | |
| 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" { |
| 611 | pub fn eql(comptime T: type, a: []const T, b: []const T) bool { | 606 | pub 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 | } |