Skip to content

Commit

Permalink
Array: fix: GC.extend adds to the current size.
Browse files Browse the repository at this point in the history
  • Loading branch information
azizk committed Jan 11, 2014
1 parent ea7a575 commit 918e411
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/dil/Array.d
Expand Up @@ -95,10 +95,10 @@ struct DArray(E)
{
auto len = this.len;
len = (len < n ? len : n); // min(len, n)
auto bytes = n * E.sizeof;
if (!ptr || GC.extend(ptr, bytes, bytes) == 0)
auto addBytes = (n <= cap ? 0 : n - cap) * E.sizeof;
if (!ptr || GC.extend(ptr, addBytes, addBytes) == 0)
{ // Couldn't extend. Allocate new memory.
auto newPtr = cast(E*)GC.malloc(bytes, scanIfPtrs);
auto newPtr = cast(E*)GC.malloc(n * E.sizeof, scanIfPtrs);
if (len) // Copy to the new block if there are elements.
newPtr[0..len] = ptr[0..len];
ptr = newPtr;
Expand Down

0 comments on commit 918e411

Please sign in to comment.