Skip to content

Commit

Permalink
Fix issue 13619 - array capacity not updated when changing length
Browse files Browse the repository at this point in the history
  • Loading branch information
byebye committed Mar 11, 2017
1 parent f156be1 commit 8ba7ce5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions std/container/array.d
Expand Up @@ -333,6 +333,7 @@ if (!is(Unqual!T == bool))
_payload = (cast(T*) realloc(_payload.ptr,
nbytes))[0 .. newLength];
initializeAll(_payload.ptr[startEmplace .. length]);
_capacity = newLength;
}

// capacity
Expand Down Expand Up @@ -1003,6 +1004,25 @@ $(D r)
assert(a.empty);
}

@system unittest
{
Array!int a;
a.length = 10;
assert(a.length == 10);
assert(a.capacity >= a.length);
}

@system unittest
{
Array!int a;
a.length = 10;
assert(a.length == 10);
assert(a.capacity >= a.length);
a.length = 5;
assert(a.length == 5);
assert(a.capacity >= a.length);
}

@system unittest
{
Array!int a = Array!int(1, 2, 3);
Expand Down Expand Up @@ -1935,10 +1955,14 @@ if (is(Unqual!T == bool))
Array!bool a;
a.length = 1057;
assert(a.length == 1057);
assert(a.capacity >= a.length);
foreach (e; a)
{
assert(!e);
}
a.length = 100;
assert(a.length == 100);
assert(a.capacity >= a.length);
}

/**
Expand Down

0 comments on commit 8ba7ce5

Please sign in to comment.