Skip to content

Commit

Permalink
Merge pull request #177 from JackStouffer/Issue-176
Browse files Browse the repository at this point in the history
Fix Issue #176: DynamicArray should use std.experimental.allocator.common.reallocate
  • Loading branch information
CyberShadow authored Sep 22, 2021
2 parents 9eaa830 + 208f5b8 commit 116a028
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/containers/dynamicarray.d
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
static if (useGC)
void* oldPtr = arr.ptr;
void[] a = cast(void[]) arr;
import std.experimental.allocator.common : reallocate;
allocator.reallocate(a, c * T.sizeof);
arr = cast(typeof(arr)) a;
static if (useGC)
Expand Down Expand Up @@ -247,6 +248,7 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
static if (useGC)
void* oldPtr = arr.ptr;
void[] a = cast(void[]) arr;
import std.experimental.allocator.common : reallocate;
allocator.reallocate(a, c * T.sizeof);
arr = cast(typeof(arr)) a;
static if (useGC)
Expand Down Expand Up @@ -682,3 +684,15 @@ version(emsi_containers_unittest) @nogc unittest
a.resize(1);
assert(a[0].i == 42);
}

version(emsi_containers_unittest) unittest
{
import std.experimental.allocator.building_blocks.region : Region;
auto region = Region!Mallocator(1024);

auto arr = DynamicArray!(int, Region!(Mallocator)*, true)(&region);
// reserve and insert back call the common form of reallocate
arr.reserve(10);
arr.insertBack(1);
assert(arr[0] == 1);
}

0 comments on commit 116a028

Please sign in to comment.