Skip to content

Commit e49ec32

Browse files
committed
Fix mir.array.allocation.array
1 parent 78322f7 commit e49ec32

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

source/mir/appender.d

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import mir.conv: _mir_destroy = xdestroy;
1212
private extern(C) @system nothrow @nogc pure void* memcpy(scope void* s1, scope const void* s2, size_t n);
1313

1414

15-
///
15+
/++
16+
The buffer uses stack memory and C Runtime to allocate temporal memory.
17+
18+
Shouldn't store references to GC allocated data.
19+
+/
1620
struct ScopedBuffer(T, size_t bytes = 4096)
1721
if (bytes && T.sizeof <= bytes)
1822
{

source/mir/array/allocation.d

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ if ((isInputRange!Range || isIterable!Range) && !isInfinite!Range && !__traits(i
112112
}
113113
else
114114
{
115-
import mir.appender: scopedBuffer;
116-
import std.array: uninitializedArray;
115+
import std.array: std_appender = appender;
117116

118-
auto a = scopedBuffer!(Unqual!E);
117+
auto a = std_appender!(E[]);
119118

120119
static if (isInputRange!Range)
121120
for (; !r.empty; r.popFront)
@@ -131,12 +130,7 @@ if ((isInputRange!Range || isIterable!Range) && !isInfinite!Range && !__traits(i
131130
foreach (e; r)
132131
a.put(forward!e);
133132
}
134-
135-
return () @trusted {
136-
auto ret = uninitializedArray!(Unqual!E[])(a.length);
137-
a.moveDataAndEmplaceTo(ret);
138-
return ret;
139-
} ();
133+
return a.data;
140134
}
141135
}
142136

0 commit comments

Comments
 (0)