| ... | @@ -125,6 +125,7 @@ pub const Allocator = struct { | ... | @@ -125,6 +125,7 @@ pub const Allocator = struct { |
| 125 | | 125 | |
| 126 | /// Copy all of source into dest at position 0. | 126 | /// Copy all of source into dest at position 0. |
| 127 | /// dest.len must be >= source.len. | 127 | /// dest.len must be >= source.len. |
| | 128 | /// dest.ptr must be <= src.ptr. |
| 128 | pub fn copy(comptime T: type, dest: []T, source: []const T) void { | 129 | pub fn copy(comptime T: type, dest: []T, source: []const T) void { |
| 129 | // TODO instead of manually doing this check for the whole array | 130 | // TODO instead of manually doing this check for the whole array |
| 130 | // and turning off runtime safety, the compiler should detect loops like | 131 | // and turning off runtime safety, the compiler should detect loops like |
| ... | @@ -135,6 +136,23 @@ pub fn copy(comptime T: type, dest: []T, source: []const T) void { | ... | @@ -135,6 +136,23 @@ pub fn copy(comptime T: type, dest: []T, source: []const T) void { |
| 135 | dest[i] = s; | 136 | dest[i] = s; |
| 136 | } | 137 | } |
| 137 | | 138 | |
| | 139 | /// Copy all of source into dest at position 0. |
| | 140 | /// dest.len must be >= source.len. |
| | 141 | /// dest.ptr must be >= src.ptr. |
| | 142 | pub fn copyBackwards(comptime T: type, dest: []T, source: []const T) void { |
| | 143 | // TODO instead of manually doing this check for the whole array |
| | 144 | // and turning off runtime safety, the compiler should detect loops like |
| | 145 | // this and automatically omit safety checks for loops |
| | 146 | @setRuntimeSafety(false); |
| | 147 | assert(dest.len >= source.len); |
| | 148 | var i = source.len; |
| | 149 | while(i > 0){ |
| | 150 | i -= 1; |
| | 151 | dest[i] = source[i]; |
| | 152 | } |
| | 153 | } |
| | 154 | |
| | 155 | |
| 138 | pub fn set(comptime T: type, dest: []T, value: T) void { | 156 | pub fn set(comptime T: type, dest: []T, value: T) void { |
| 139 | for (dest) |*d| | 157 | for (dest) |*d| |
| 140 | d.* = value; | 158 | d.* = value; |