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

Commit

Permalink
When allocating a struct with "new", do not pass the pointer type inf…
Browse files Browse the repository at this point in the history
…o to the runtime, but the struct type info.

The fix also provides a small performance improvement as it no longer calls the virtual function TypeInfo.next() multiple times
  • Loading branch information
rainers committed Aug 31, 2014
1 parent bd1557a commit 6b9e781
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/rt/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -1009,9 +1009,7 @@ extern (C) void[] _d_newarraymiT(const TypeInfo ti, size_t ndims, ...)

extern (C) void* _d_newitemT(TypeInfo ti)
{
// BUG ti is actually still the array typeinfo. Not that this is a
// difficult thing to workaround...
auto size = ti.next.tsize; // array element size
auto size = ti.tsize; // array element size

debug(PRINTF) printf("_d_newitemT(size = %d)\n", size);
/* not sure if we need this...
Expand All @@ -1020,7 +1018,7 @@ extern (C) void* _d_newitemT(TypeInfo ti)
else
{*/
// allocate a block to hold this item
auto ptr = GC.malloc(size, !(ti.next.flags & 1) ? BlkAttr.NO_SCAN : 0, ti);
auto ptr = GC.malloc(size, !(ti.flags & 1) ? BlkAttr.NO_SCAN : 0, ti);
debug(PRINTF) printf(" p = %p\n", ptr);
if(size == ubyte.sizeof)
*cast(ubyte*)ptr = 0;
Expand All @@ -1037,21 +1035,19 @@ extern (C) void* _d_newitemT(TypeInfo ti)

extern (C) void* _d_newitemiT(TypeInfo ti)
{
// BUG ti is actually still the array typeinfo. Not that this is a
// difficult thing to workaround...
auto size = ti.next.tsize; // array element size
auto size = ti.tsize; // array element size

debug(PRINTF) printf("_d_newitemiT(size = %d)\n", size);

/*if (length == 0 || size == 0)
result = null;
else
{*/
auto initializer = ti.next.init();
auto initializer = ti.init();
auto isize = initializer.length;
auto q = initializer.ptr;

auto ptr = GC.malloc(size, !(ti.next.flags & 1) ? BlkAttr.NO_SCAN : 0, ti);
auto ptr = GC.malloc(size, !(ti.flags & 1) ? BlkAttr.NO_SCAN : 0, ti);
debug(PRINTF) printf(" p = %p\n", ptr);
if (isize == 1)
*cast(ubyte*)ptr = *cast(ubyte*)q;
Expand Down

0 comments on commit 6b9e781

Please sign in to comment.