Given code such as the following:
struct Vector3i {
int[3] array;
this(int[3] array...) { this.array = array; }
}
void main() {
auto vec = Vector3i(1, 2, 3);
}
When compiled with optimisation and inlining turned on, the generated code will write to the fixed size array 5 times in the process of initialisation:
1) Write zeros to "vec.array"
2) Write zeros to temporary argument array
3) Write 1, 2, 3 to temporary variables
4) Copy temporary variables into temporary argument array
5) Call "memcpy" to copy temporary argument array to "vec.array"
Clearly this could be done by simply writing 1, 2, 3 to "vec.array". It seems like any optimisations on these sort of operations would speed up a lot of code...
Comment #1 by bearophile_hugs — 2013-05-15T03:22:50Z
See also Issue 5212
Comment #2 by robert.schadek — 2024-12-13T18:06:53Z