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

Commit

Permalink
move struct TypeInfo to the end of the memory block, after SMALLPAD/M…
Browse files Browse the repository at this point in the history
…EDPAD
  • Loading branch information
rainers authored and Orvid committed Jan 13, 2015
1 parent 3a04463 commit 2b55785
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/rt/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ bool __setArrayAllocLength(ref BlkInfo info, size_t newlength, bool isshared, co
if(newlength + SMALLPAD + typeInfoSize > info.size)
// new size does not fit inside block
return false;
auto length = cast(ubyte *)(info.base + info.size - SMALLPAD);
auto length = cast(ubyte *)(info.base + info.size - typeInfoSize - SMALLPAD);
if(oldlength != ~0)
{
if(isshared)
Expand Down Expand Up @@ -269,7 +269,7 @@ bool __setArrayAllocLength(ref BlkInfo info, size_t newlength, bool isshared, co
}
if (typeInfoSize)
{
auto typeInfo = cast(TypeInfo_Struct*)(info.base + info.size - SMALLPAD - size_t.sizeof);
auto typeInfo = cast(TypeInfo_Struct*)(info.base + info.size - size_t.sizeof);
*typeInfo = cast(TypeInfo_Struct)ti.next;
}
}
Expand All @@ -278,7 +278,7 @@ bool __setArrayAllocLength(ref BlkInfo info, size_t newlength, bool isshared, co
if(newlength + MEDPAD + typeInfoSize > info.size)
// new size does not fit inside block
return false;
auto length = cast(ushort *)(info.base + info.size - MEDPAD);
auto length = cast(ushort *)(info.base + info.size - typeInfoSize - MEDPAD);
if(oldlength != ~0)
{
if(isshared)
Expand Down Expand Up @@ -308,7 +308,7 @@ bool __setArrayAllocLength(ref BlkInfo info, size_t newlength, bool isshared, co
}
if (typeInfoSize)
{
auto typeInfo = cast(TypeInfo_Struct*)(info.base + info.size - MEDPAD - size_t.sizeof);
auto typeInfo = cast(TypeInfo_Struct*)(info.base + info.size - size_t.sizeof);
*typeInfo = cast(TypeInfo_Struct)ti.next;
}
}
Expand Down Expand Up @@ -699,13 +699,13 @@ Lcontinue:
{
if(info.size <= 256)
{
curallocsize = *(cast(ubyte *)(info.base + info.size - SMALLPAD));
arraypad = SMALLPAD + structTypeInfoSize(ti.next);
curallocsize = *(cast(ubyte *)(info.base + info.size - arraypad));
}
else if(info.size < PAGESIZE)
{
curallocsize = *(cast(ushort *)(info.base + info.size - MEDPAD));
arraypad = MEDPAD + structTypeInfoSize(ti.next);
curallocsize = *(cast(ushort *)(info.base + info.size - arraypad));
}
else
{
Expand Down Expand Up @@ -1259,10 +1259,8 @@ extern (C) int rt_hasArrayFinalizerInSegment(void* p, size_t size, in void[] seg
return false;

TypeInfo_Struct si = void;
if(size <= 256)
si = *cast(TypeInfo_Struct*)(p + size - SMALLPAD - size_t.sizeof);
else if (size < PAGESIZE)
si = *cast(TypeInfo_Struct*)(p + size - MEDPAD - size_t.sizeof);
if (size < PAGESIZE)
si = *cast(TypeInfo_Struct*)(p + size - size_t.sizeof);
else
si = *cast(TypeInfo_Struct*)(p + size_t.sizeof);

Expand All @@ -1280,13 +1278,13 @@ extern (C) void rt_finalize_array2(void* p, size_t size, bool resetMemory = true
TypeInfo_Struct si = void;
if(size <= 256)
{
si = *cast(TypeInfo_Struct*)(p + size - SMALLPAD - size_t.sizeof);
size = *cast(ubyte*)(p + size - SMALLPAD);
si = *cast(TypeInfo_Struct*)(p + size - size_t.sizeof);
size = *cast(ubyte*)(p + size - size_t.sizeof - SMALLPAD);
}
else if (size < PAGESIZE)
{
si = *cast(TypeInfo_Struct*)(p + size - MEDPAD - size_t.sizeof);
size = *cast(ushort*)(p + size - MEDPAD);
si = *cast(TypeInfo_Struct*)(p + size - size_t.sizeof);
size = *cast(ushort*)(p + size - size_t.sizeof - MEDPAD);
}
else
{
Expand Down

0 comments on commit 2b55785

Please sign in to comment.