Skip to content

Commit

Permalink
Merge pull request #389 from vibe-d/fix_allocaappender
Browse files Browse the repository at this point in the history
Fix buffer growth in AllocAppender
  • Loading branch information
l-kramer committed Feb 15, 2024
2 parents 7823db6 + 37efe37 commit 230faa5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion source/vibe/internal/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ struct AllocAppender(ArrayType : E[], E) {
reserve(new_size - m_data.length + m_remaining.length);
}

private auto withAlloc(string method, ARGS...)(ARGS args)
private auto withAlloc(string method, ARGS...)(auto ref ARGS args)
{
static if (is(RCIAllocator)) {
if (!m_rcAlloc.isNull) return __traits(getMember, m_rcAlloc, method)(args);
Expand Down Expand Up @@ -252,6 +252,14 @@ unittest {
assert(app.data == "foo");
}

unittest {
auto app = AllocAppender!string(theAllocator);
app.reserve(3);
app.put("foo");
app.put("bar");
assert(app.data == "foobar");
}


struct FixedAppender(ArrayType : E[], size_t NELEM, E) {
alias ElemType = Unqual!E;
Expand Down

0 comments on commit 230faa5

Please sign in to comment.