Struct Constructor Lazy
Biotronic via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 12 04:57:33 PDT 2017
On Wednesday, 12 July 2017 at 11:34:45 UTC, Jiyan wrote:
> Hey,
> yes i did but to be honest i used dmd in debug version.
> The thing about the static one, is that it creates a local
> object A isnt that a performance issue itself - or am i wrong -
> im confused actually :P?
Debug = no optimization. Looking at the generated assembly in a
debug build is worthless.
You raise a valid point. In a debug build, you're probably right
- it will need to copy the temporary to the target. With
optimizations enabled, NRVO[0] will populate the target directly,
resulting in roughly the equivalent of this code:
struct A {
int field;
static void opCall(A* p) {
p.field = getDataFromFile("file.txt");
}
}
A a;
A(&a);
If the function is inlined, the whole problem is of course moot.
There are probably other optimizations that can interfere with
what I've described.
--
Biotronic
[0]: https://en.wikipedia.org/wiki/Return_value_optimization
More information about the Digitalmars-d-learn
mailing list