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

Commit

Permalink
refactor: remove unnecessary object._rawDup() template
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Aug 30, 2016
1 parent 35cd635 commit 26b77b5
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/object.d
Expand Up @@ -3323,8 +3323,8 @@ unittest
/// ditto
@property T[] dup(T:void)(scope const(T)[] a) @trusted
{
if (__ctfe) assert(0, "Cannot dup a void[] array at compile time.");
return cast(T[])_rawDup(a);
import core.internal.traits : Unconst;
return _dup!(const(T), Unconst!T)(a);
}

/// Provide the .idup array property.
Expand Down Expand Up @@ -3355,28 +3355,30 @@ private U[] _dup(T, U)(scope T[] a) // pure nothrow depends on postblit
{
if (__ctfe)
{
U[] res;
foreach (ref e; a)
res ~= e;
return res;
static if (is(T : void))
assert(0, "Cannot dup a void[] array at compile time.");
else
{
U[] res;
foreach (ref e; a)
res ~= e;
return res;
}
}

a = _rawDup(a);
auto res = *cast(typeof(return)*)&a;
_doPostblit(res);
import core.stdc.string : memcpy;

void[] arr = _d_newarrayU(typeid(T[]), a.length);
memcpy(arr.ptr, cast(const(void)*)a.ptr, T.sizeof * a.length);
auto res = *cast(U[]*)&arr;

static if (!is(T : void))
_doPostblit(res);
return res;
}

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

private inout(T)[] _rawDup(T)(scope inout(T)[] a)
{
import core.stdc.string : memcpy;

void[] arr = _d_newarrayU(typeid(T[]), a.length);
memcpy(arr.ptr, cast(void*)a.ptr, T.sizeof * a.length);
return *cast(inout(T)[]*)&arr;
}

private template _PostBlitType(T)
{
Expand Down

0 comments on commit 26b77b5

Please sign in to comment.