Repository navigation
Expand file tree
/
Copy patharray.d
More file actions
executable file
·92 lines (80 loc) · 1.88 KB
/
Copy patharray.d
File metadata and controls
executable file
·92 lines (80 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module std.performance.array;
import std.range : isOutputRange;
import std.traitsExt : Dequal;
@trusted pure struct Appender(A : QE[], QE)
{
alias E = Dequal!QE;
private static class InnerData
{
E[] mBuffer;
size_t nextI = 0;
}
private InnerData mData;
private void ensureCreated() @trusted pure nothrow
{
if (!mData)
mData = new InnerData();
}
private void ensureSpace(size_t len) @trusted pure nothrow
{
ensureCreated();
while (mData.nextI + len >= mData.mBuffer.length)
mData.mBuffer.length = (mData.mBuffer.length ? mData.mBuffer.length : 1) << 1;
}
@property A data() @trusted pure
{
ensureCreated();
return cast(A)mData.mBuffer[0..mData.nextI].dup;
}
void reset() @trusted pure nothrow
{
ensureCreated();
mData.nextI = 0;
}
void clear() @trusted pure nothrow
{
ensureCreated();
mData.nextI = 0;
mData.mBuffer[] = E.init;
}
void put(QE[] arr) @trusted pure nothrow
{
ensureCreated();
ensureSpace(arr.length);
// This is required due to a compiler bug somewhere.....
if (__ctfe && !is(E == char))
{
for (auto i = mData.nextI, i2 = 0; i < arr.length + mData.nextI; i++, i2++)
mData.mBuffer[i] = arr[i2];
}
else
mData.mBuffer[mData.nextI..arr.length + mData.nextI] = cast(E[])arr[];
mData.nextI += arr.length;
}
void put(QE e) @trusted pure nothrow
{
ensureCreated();
ensureSpace(1);
mData.mBuffer[mData.nextI] = e;
mData.nextI++;
}
static if (!is(QE == E))
{
void put(E[] arr) @trusted pure nothrow
{
ensureCreated();
ensureSpace(arr.length);
mData.mBuffer[mData.nextI..arr.length + mData.nextI] = arr[0..$];
mData.nextI += arr.length;
}
void put(E e) @trusted pure nothrow
{
ensureCreated();
ensureSpace(1);
mData.mBuffer[mData.nextI] = e;
mData.nextI++;
}
}
}
static assert(isOutputRange!(Appender!string, string));
static assert(isOutputRange!(Appender!(ubyte[]), ubyte[]));