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

Commit bd67a95

Browse files
authored
Merge pull request #3034 from n8sh/issue-20741
`dup`, `idup`, `keys`, `values`: if a type is known to have a postblit do not emit code for the non-postblit path and vice versa merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2 parents 327f73f + 93bee22 commit bd67a95

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
@@ -2347,8 +2347,9 @@ V[K] dup(T : V[K], K, V)(T aa)
23472347
return *cast(V*)pv;
23482348
}
23492349

2350-
if (auto postblit = _getPostblit!V())
2350+
static if (__traits(hasPostblit, V))
23512351
{
2352+
auto postblit = _getPostblit!V();
23522353
foreach (k, ref v; aa)
23532354
postblit(duplicateElem(k, v));
23542355
}
@@ -2560,7 +2561,8 @@ Key[] keys(T : Value[Key], Value, Key)(T aa) @property
25602561
const(Value[Key]) realAA = aa;
25612562
auto a = cast(void[])_aaKeys(*cast(inout(AA)*)&realAA, Key.sizeof, typeid(Key[]));
25622563
auto res = *cast(Key[]*)&a;
2563-
_doPostblit(res);
2564+
static if (__traits(hasPostblit, Key))
2565+
_doPostblit(res);
25642566
return res;
25652567
}
25662568

@@ -2611,7 +2613,8 @@ Value[] values(T : Value[Key], Value, Key)(T aa) @property
26112613
const(Value[Key]) realAA = aa;
26122614
auto a = cast(void[])_aaValues(*cast(inout(AA)*)&realAA, Key.sizeof, Value.sizeof, typeid(Value[]));
26132615
auto res = *cast(Value[]*)&a;
2614-
_doPostblit(res);
2616+
static if (__traits(hasPostblit, Value))
2617+
_doPostblit(res);
26152618
return res;
26162619
}
26172620

@@ -3101,7 +3104,7 @@ private U[] _dup(T, U)(T[] a) // pure nothrow depends on postblit
31013104
memcpy(arr.ptr, cast(const(void)*)a.ptr, T.sizeof * a.length);
31023105
auto res = *cast(U[]*)&arr;
31033106

3104-
static if (!is(T : void))
3107+
static if (__traits(hasPostblit, T))
31053108
_doPostblit(res);
31063109
return res;
31073110
}
@@ -3325,8 +3328,9 @@ private auto _getPostblit(T)() @trusted pure nothrow @nogc
33253328
private void _doPostblit(T)(T[] arr)
33263329
{
33273330
// infer static postblit type, run postblit if any
3328-
if (auto postblit = _getPostblit!T())
3331+
static if (__traits(hasPostblit, T))
33293332
{
3333+
auto postblit = _getPostblit!T();
33303334
foreach (ref elem; arr)
33313335
postblit(elem);
33323336
}

0 commit comments

Comments
 (0)