Skip to content

Commit 62780da

Browse files
kinkedlang-bot
authored andcommitted
Prefer __traits(initSymbol) over TypeInfo.initializer()
1 parent cd73892 commit 62780da

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

std/algorithm/mutation.d

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -886,31 +886,13 @@ if (isInputRange!Range && hasLvalueElements!Range && hasAssignableElements!Range
886886
static if (hasElaborateAssign!T)
887887
{
888888
import std.algorithm.internal : addressOf;
889-
//Elaborate opAssign. Must go the memcpy road.
890-
//We avoid calling emplace here, because our goal is to initialize to
891-
//the static state of T.init,
892-
//So we want to avoid any un-necassarilly CC'ing of T.init
889+
//Elaborate opAssign. Must go the memcpy/memset road.
893890
static if (!__traits(isZeroInit, T))
894891
{
895-
auto p = typeid(T).initializer();
896892
for ( ; !range.empty ; range.popFront() )
897893
{
898-
static if (__traits(isStaticArray, T))
899-
{
900-
// static array initializer only contains initialization
901-
// for one element of the static array.
902-
auto elemp = cast(void *) addressOf(range.front);
903-
auto endp = elemp + T.sizeof;
904-
while (elemp < endp)
905-
{
906-
memcpy(elemp, p.ptr, p.length);
907-
elemp += p.length;
908-
}
909-
}
910-
else
911-
{
912-
memcpy(addressOf(range.front), p.ptr, T.sizeof);
913-
}
894+
import core.internal.lifetime : emplaceInitializer;
895+
emplaceInitializer(range.front);
914896
}
915897
}
916898
else
@@ -1456,10 +1438,7 @@ private void moveEmplaceImpl(T)(ref scope T target, ref return scope T source)
14561438
static if (__traits(isZeroInit, T))
14571439
() @trusted { memset(&source, 0, sz); }();
14581440
else
1459-
{
1460-
auto init = typeid(T).initializer();
1461-
() @trusted { memcpy(&source, init.ptr, sz); }();
1462-
}
1441+
() @trusted { memcpy(&source, __traits(initSymbol, T).ptr, sz); }();
14631442
}
14641443
}
14651444
else static if (isStaticArray!T)

0 commit comments

Comments
 (0)