summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sashihara <21227491+n8sh@users.noreply.github.com>2018-10-19 02:20:13 -0400
committerNathan Sashihara <21227491+n8sh@users.noreply.github.com>2018-10-21 18:52:02 -0400
commit4e8c9bd28fe6c6569814ffa3854544e11b1d346b (patch)
tree3a2dde1fd68dda93ba2aba0b18412d1d5591a3d8
parent3b5709821aa8023b628e2e4957372a2b665cb5cf (diff)
downloadtanya-4e8c9bd28fe6c6569814ffa3854544e11b1d346b.tar.gz
Use new __traits(isZeroInit) to check for a null initializer at compile time instead of runtime
-rw-r--r--source/tanya/algorithm/mutation.d13
-rw-r--r--source/tanya/conv.d12
2 files changed, 20 insertions, 5 deletions
diff --git a/source/tanya/algorithm/mutation.d b/source/tanya/algorithm/mutation.d
index daff07c..550afdd 100644
--- a/source/tanya/algorithm/mutation.d
+++ b/source/tanya/algorithm/mutation.d
@@ -89,13 +89,20 @@ do
static if (hasElaborateCopyConstructor!T || hasElaborateDestructor!T)
{
- if (typeid(T).initializer().ptr is null)
+ static if (__VERSION__ >= 2083) // __traits(isZeroInit) available.
{
- deinitialize!true(source);
+ deinitialize!(__traits(isZeroInit, T))(source);
}
else
{
- deinitialize!false(source);
+ if (typeid(T).initializer().ptr is null)
+ {
+ deinitialize!true(source);
+ }
+ else
+ {
+ deinitialize!false(source);
+ }
}
}
}
diff --git a/source/tanya/conv.d b/source/tanya/conv.d
index 48cd11a..e19ea7f 100644
--- a/source/tanya/conv.d
+++ b/source/tanya/conv.d
@@ -185,8 +185,16 @@ out(result; memory.ptr is result)
}
else
{
- static const T init = T.init;
- trustedCopy(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);
+ }
}
result.__ctor(args);
}