Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 93bee22

Browse files
committed
Fix Issue 20741 - dup, idup for arrays plus keys, values for built-in associative arrays: if a type is known to have a postblit do not emit code for the non-postblit path and vice versa
1 parent a7df07c commit 93bee22

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/object.d

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,8 +2266,9 @@ V[K] dup(T : V[K], K, V)(T aa)
22662266
return *cast(V*)pv;
22672267
}
22682268

2269-
if (auto postblit = _getPostblit!V())
2269+
static if (__traits(hasPostblit, V))
22702270
{
2271+
auto postblit = _getPostblit!V();
22712272
foreach (k, ref v; aa)
22722273
postblit(duplicateElem(k, v));
22732274
}
@@ -2479,7 +2480,8 @@ Key[] keys(T : Value[Key], Value, Key)(T aa) @property
24792480
const(Value[Key]) realAA = aa;
24802481
auto a = cast(void[])_aaKeys(*cast(inout(AA)*)&realAA, Key.sizeof, typeid(Key[]));
24812482
auto res = *cast(Key[]*)&a;
2482-
_doPostblit(res);
2483+
static if (__traits(hasPostblit, Key))
2484+
_doPostblit(res);
24832485
return res;
24842486
}
24852487

@@ -2530,7 +2532,8 @@ Value[] values(T : Value[Key], Value, Key)(T aa) @property
25302532
const(Value[Key]) realAA = aa;
25312533
auto a = cast(void[])_aaValues(*cast(inout(AA)*)&realAA, Key.sizeof, Value.sizeof, typeid(Value[]));
25322534
auto res = *cast(Value[]*)&a;
2533-
_doPostblit(res);
2535+
static if (__traits(hasPostblit, Value))
2536+
_doPostblit(res);
25342537
return res;
25352538
}
25362539

@@ -3020,7 +3023,7 @@ private U[] _dup(T, U)(T[] a) // pure nothrow depends on postblit
30203023
memcpy(arr.ptr, cast(const(void)*)a.ptr, T.sizeof * a.length);
30213024
auto res = *cast(U[]*)&arr;
30223025

3023-
static if (!is(T : void))
3026+
static if (__traits(hasPostblit, T))
30243027
_doPostblit(res);
30253028
return res;
30263029
}
@@ -3244,8 +3247,9 @@ private auto _getPostblit(T)() @trusted pure nothrow @nogc
32443247
private void _doPostblit(T)(T[] arr)
32453248
{
32463249
// infer static postblit type, run postblit if any
3247-
if (auto postblit = _getPostblit!T())
3250+
static if (__traits(hasPostblit, T))
32483251
{
3252+
auto postblit = _getPostblit!T();
32493253
foreach (ref elem; arr)
32503254
postblit(elem);
32513255
}

0 commit comments

Comments
 (0)