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

Commit 26b77b5

Browse files
committed
refactor: remove unnecessary object._rawDup() template
1 parent 35cd635 commit 26b77b5

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/object.d

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,8 +3323,8 @@ unittest
33233323
/// ditto
33243324
@property T[] dup(T:void)(scope const(T)[] a) @trusted
33253325
{
3326-
if (__ctfe) assert(0, "Cannot dup a void[] array at compile time.");
3327-
return cast(T[])_rawDup(a);
3326+
import core.internal.traits : Unconst;
3327+
return _dup!(const(T), Unconst!T)(a);
33283328
}
33293329

33303330
/// Provide the .idup array property.
@@ -3355,28 +3355,30 @@ private U[] _dup(T, U)(scope T[] a) // pure nothrow depends on postblit
33553355
{
33563356
if (__ctfe)
33573357
{
3358-
U[] res;
3359-
foreach (ref e; a)
3360-
res ~= e;
3361-
return res;
3358+
static if (is(T : void))
3359+
assert(0, "Cannot dup a void[] array at compile time.");
3360+
else
3361+
{
3362+
U[] res;
3363+
foreach (ref e; a)
3364+
res ~= e;
3365+
return res;
3366+
}
33623367
}
33633368

3364-
a = _rawDup(a);
3365-
auto res = *cast(typeof(return)*)&a;
3366-
_doPostblit(res);
3369+
import core.stdc.string : memcpy;
3370+
3371+
void[] arr = _d_newarrayU(typeid(T[]), a.length);
3372+
memcpy(arr.ptr, cast(const(void)*)a.ptr, T.sizeof * a.length);
3373+
auto res = *cast(U[]*)&arr;
3374+
3375+
static if (!is(T : void))
3376+
_doPostblit(res);
33673377
return res;
33683378
}
33693379

33703380
private extern (C) void[] _d_newarrayU(const TypeInfo ti, size_t length) pure nothrow;
33713381

3372-
private inout(T)[] _rawDup(T)(scope inout(T)[] a)
3373-
{
3374-
import core.stdc.string : memcpy;
3375-
3376-
void[] arr = _d_newarrayU(typeid(T[]), a.length);
3377-
memcpy(arr.ptr, cast(void*)a.ptr, T.sizeof * a.length);
3378-
return *cast(inout(T)[]*)&arr;
3379-
}
33803382

33813383
private template _PostBlitType(T)
33823384
{

0 commit comments

Comments
 (0)