manual_memcpy
Finds for i: 0..n-1 { dst[i] = src[i]; }, an element-by-element copy memcpy does at once.
Category perf, warn by default.
#import "Basic";
copy_all :: (dst: *int, src: [] int, count: int) {
for i: 0..count - 1 {
dst[i] = src[i];
}
}
main :: () {
values := int.[1, 2, 3, 4];
out: [4] int;
copy_all(out.data, values, 4);
print("%\n", out);
}warning[manual_memcpy]: this loop copies `src` into `dst` one element at a time
--> example.jai:4:5
|
4 | for i: 0..count - 1 {
| ^^^^^^^^^^^^^^^^^^^^
|
= help: copy the elements at once: `memcpy(dst, src.data, count * size_of(s64))`
= note: `manual_memcpy` is `warn` by default#import "Basic";
copy_all :: (dst: *int, src: [] int, count: int) {
memcpy(dst, src.data, count * size_of(int));
}
main :: () {
values := int.[1, 2, 3, 4];
out: [4] int;
copy_all(out.data, values, 4);
print("%\n", out);
}Fires on a for over a range starting at 0 whose only statement is dst[i] = src[i]; with i the loop's variable, dst and src different names or member paths, both arrays or pointers, and the same element type on both sides.