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

Commit

Permalink
Use GC.qalloc rather than GC.malloc + GC.sizeOf.
Browse files Browse the repository at this point in the history
Also fixed the BlkInfo calculations to account for the sentinal bytes.
  • Loading branch information
Orvid committed Jan 13, 2015
1 parent 381419e commit 17b9522
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/gc/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ struct Gcx
if (pool.structFinals.nbits && pool.structFinals.test(biti))
{
if (pool.appendable.nbits && pool.appendable.test(biti) && rt_hasArrayFinalizerInSegment(sentinel_add(p), segment))
rt_finalize_array2(sentinel_add(p), BlkInfo(p, pool.bPageOffsets[pn] * PAGESIZE), true, true);
rt_finalize_array2(sentinel_add(p), BlkInfo(sentinel_add(p), (pool.bPageOffsets[pn] * PAGESIZE) - SENTINEL_EXTRA), true, true);
else if (rt_hasStructFinalizerInSegment(sentinel_add(p), segment))
rt_finalize_struct(sentinel_add(p), false, true);
else
Expand Down Expand Up @@ -1617,7 +1617,7 @@ struct Gcx
if (pool.structFinals.nbits && pool.structFinals.test(biti))
{
if (pool.appendable.nbits && pool.appendable.test(biti) && rt_hasArrayFinalizerInSegment(sentinel_add(p), segment))
rt_finalize_array2(sentinel_add(p), BlkInfo(p, size), true, true);
rt_finalize_array2(sentinel_add(p), BlkInfo(sentinel_add(p), size - SENTINEL_EXTRA), true, true);
else if (rt_hasStructFinalizerInSegment(sentinel_add(p), segment))
rt_finalize_struct(sentinel_add(p), false, true);
else
Expand Down Expand Up @@ -2668,7 +2668,7 @@ struct Gcx
if (pool.structFinals.nbits && pool.structFinals.testClear(biti))
{
if (pool.appendable.nbits && pool.appendable.test(biti))
rt_finalize_array2(sentinel_add(p), BlkInfo(p, pool.bPageOffsets[pn] * PAGESIZE), true, true);
rt_finalize_array2(sentinel_add(p), BlkInfo(sentinel_add(p), (pool.bPageOffsets[pn] * PAGESIZE) - SENTINEL_EXTRA), true, true);
else
rt_finalize_struct(sentinel_add(p), false, true);
}
Expand Down Expand Up @@ -2747,7 +2747,7 @@ struct Gcx
if (pool.structFinals.nbits && pool.structFinals.test(biti))
{
if (pool.appendable.nbits && pool.appendable.test(biti))
rt_finalize_array2(sentinel_add(p), BlkInfo(p, size), true, true);
rt_finalize_array2(sentinel_add(p), BlkInfo(sentinel_add(p), size - SENTINEL_EXTRA), true, true);
else
rt_finalize_struct(sentinel_add(p), false, true);
}
Expand Down
10 changes: 6 additions & 4 deletions src/rt/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,8 @@ extern (C) void* _d_newitemT(TypeInfo ti)
else
{*/
// allocate a block to hold this item
auto ptr = GC.malloc(size, baseFlags, ti);
auto blkInf = GC.qalloc(size, baseFlags, ti);
auto ptr = blkInf.base;
debug(PRINTF) printf(" p = %p\n", ptr);
if(size == ubyte.sizeof)
*cast(ubyte*)ptr = 0;
Expand All @@ -1093,7 +1094,7 @@ extern (C) void* _d_newitemT(TypeInfo ti)
memset(ptr, 0, size);

if (needsTypeInfo)
*cast(TypeInfo*)(ptr + GC.sizeOf(ptr) - size_t.sizeof) = ti;
*cast(TypeInfo*)(ptr + blkInf.size - size_t.sizeof) = ti;

return ptr;
//}
Expand Down Expand Up @@ -1124,7 +1125,8 @@ extern (C) void* _d_newitemiT(TypeInfo ti)
auto isize = initializer.length;
auto q = initializer.ptr;

auto ptr = GC.malloc(size, baseFlags, ti);
auto blkInf = GC.qalloc(size, baseFlags, ti);
auto ptr = blkInf.base;
debug(PRINTF) printf(" p = %p\n", ptr);
if (isize == 1)
*cast(ubyte*)ptr = *cast(ubyte*)q;
Expand All @@ -1136,7 +1138,7 @@ extern (C) void* _d_newitemiT(TypeInfo ti)
memcpy(ptr, q, isize);

if (needsTypeInfo)
*cast(TypeInfo*)(ptr + GC.sizeOf(ptr) - size_t.sizeof) = ti;
*cast(TypeInfo*)(ptr + blkInf.size - size_t.sizeof) = ti;
return ptr;
//}
}
Expand Down

0 comments on commit 17b9522

Please sign in to comment.