Use new __traits(isZeroInit) to check for a null initializer at compile time instead of runtime
This commit is contained in:
parent
3b5709821a
commit
4e8c9bd28f
@ -88,6 +88,12 @@ do
|
|||||||
tanya.memory.op.copy((&source)[0 .. 1], (&target)[0 .. 1]);
|
tanya.memory.op.copy((&source)[0 .. 1], (&target)[0 .. 1]);
|
||||||
|
|
||||||
static if (hasElaborateCopyConstructor!T || hasElaborateDestructor!T)
|
static if (hasElaborateCopyConstructor!T || hasElaborateDestructor!T)
|
||||||
|
{
|
||||||
|
static if (__VERSION__ >= 2083) // __traits(isZeroInit) available.
|
||||||
|
{
|
||||||
|
deinitialize!(__traits(isZeroInit, T))(source);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (typeid(T).initializer().ptr is null)
|
if (typeid(T).initializer().ptr is null)
|
||||||
{
|
{
|
||||||
@ -99,6 +105,7 @@ do
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
target = source;
|
target = source;
|
||||||
|
@ -185,9 +185,17 @@ out(result; memory.ptr is result)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
static const T init = T.init;
|
static if (__VERSION__ >= 2083 // __traits(isZeroInit) available.
|
||||||
|
&& __traits(isZeroInit, T))
|
||||||
|
{
|
||||||
|
(() @trusted => memory.ptr[0 .. T.sizeof])().fill!0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
static immutable T init = T.init;
|
||||||
trustedCopy(init);
|
trustedCopy(init);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
result.__ctor(args);
|
result.__ctor(args);
|
||||||
}
|
}
|
||||||
else static if (Args.length == 1 && is(typeof({ T t = args[0]; })))
|
else static if (Args.length == 1 && is(typeof({ T t = args[0]; })))
|
||||||
|
Loading…
Reference in New Issue
Block a user