Compiler could elide many more postblit constructor calls
TommiT
tommitissari at hotmail.com
Sat Jun 29 06:47:34 PDT 2013
Disclaimer: The "discovery" I'm about to describe here seems so
obvious that I'm inclined to think that I've made some mistake.
The sole purpose of postblit constructors is to provide value
semantics to structs which have mutable indirection (variables
which have only immutable indirection have value semantics
implicitly). Variables that are const/immutable can't have
mutable indirection. Therefore, when making a copy from a
const/immutable variable to a const/immutable variable, there's
no need to call the postblit constructor.
Example:
----
struct S
{
int[] values;
this(this)
{
values = values.dup;
}
}
void foo(const S) { }
void main()
{
const S s;
foo(s); // No need to call postblit
}
More information about the Digitalmars-d
mailing list