@@ -26,7 +26,7 @@ private extern(C) @system nothrow @nogc pure void* memcpy(scope void* s1, scope
26
26
struct ScopedBuffer (T, size_t bytes = 4096 )
27
27
if (bytes)
28
28
{
29
- import std.traits : Unqual, isMutable, isIterable, hasElaborateAssign, isAssignable, isArray;
29
+ import std.traits : Unqual, isMutable, isStaticArray, isIterable, hasElaborateAssign, isAssignable, isArray;
30
30
import mir.primitives: hasLength;
31
31
import mir.conv: emplaceRef;
32
32
@@ -88,7 +88,6 @@ struct ScopedBuffer(T, size_t bytes = 4096)
88
88
sizediff_t t = _currentLength - n;
89
89
if (t < 0 )
90
90
assert (0 , " ScopedBffer.popBackN: n is too large." );
91
- import mir.exception;
92
91
data[t .. _currentLength]._mir_destroy;
93
92
_currentLength = t;
94
93
}
@@ -97,15 +96,15 @@ struct ScopedBuffer(T, size_t bytes = 4096)
97
96
void put (T e) @safe scope
98
97
{
99
98
auto cl = _currentLength;
100
- prepare(1 );
99
+ auto d = prepare(1 );
101
100
static if (isMutable! T)
102
101
{
103
102
import core.lifetime : move;
104
- emplaceRef! (Unqual! T)(data [cl], e.move);
103
+ emplaceRef! (Unqual! T)(d [cl], e.move);
105
104
}
106
105
else
107
106
{
108
- emplaceRef! (Unqual! T)(data [cl], e);
107
+ emplaceRef! (Unqual! T)(d [cl], e);
109
108
}
110
109
}
111
110
@@ -118,57 +117,32 @@ struct ScopedBuffer(T, size_t bytes = 4096)
118
117
emplaceRef! (Unqual! T)(d[cl], e);
119
118
}
120
119
121
- static if (! hasElaborateAssign! T && isAssignable! (T, const T))
122
- // /
123
- void put (scope const (T)[] e) scope
124
- {
125
- auto cl = _currentLength;
126
- auto d = prepare(e.length);
127
- auto len = e.length * T.sizeof;
128
- if (! __ctfe)
129
- (()@trusted => memcpy(cast (void * )(d.ptr + cl), e.ptr, len))();
130
- else
131
- (()@trusted { (d.ptr + cl)[0 .. len] = e[0 .. len]; })();
132
- }
133
-
134
- static if (! hasElaborateAssign! T && ! isAssignable! (T, const T))
120
+ static if (! hasElaborateAssign! T)
135
121
// /
136
- void put ()( scope T [] e) scope
122
+ void put (scope R [] e) scope
137
123
{
138
124
auto cl = _currentLength;
139
125
auto d = prepare(e.length);
140
- auto len = e.length * T.sizeof;
141
126
if (! __ctfe)
142
- (()@trusted => memcpy(cast (void * )(d.ptr + cl), e.ptr, len ))();
127
+ (()@trusted => memcpy(cast (void * )(d.ptr + cl), e.ptr, e.length * T.sizeof ))();
143
128
else
144
- (() @trusted {
145
- foreach (i; 0 .. cl)
146
- d[i].emplaceRef ! T(e[i]);
147
- })( );
129
+ static if (isMutable ! T)
130
+ (() @trusted => d[cl .. cl + e.length] = e)();
131
+ else
132
+ assert ( 0 );
148
133
}
149
134
150
135
// /
151
136
void put (Iterable)(Iterable range) scope
152
- if (isIterable! Iterable && (! isArray! Iterable || hasElaborateAssign! T))
137
+ if (isIterable! Iterable && ! isStaticArray ! Iterable && (! isArray! Iterable || hasElaborateAssign! T))
153
138
{
154
139
static if (hasLength! Iterable)
155
140
{
156
141
auto cl = _currentLength;
157
142
auto d = prepare(range.length);
158
- static if (is (Iterable : R[]) && ! hasElaborateAssign! T)
159
- {
160
- auto len = range.length * T.sizeof;
161
- if (! __ctfe)
162
- (()@trusted => memcpy(d.ptr + cl, e.ptr, len))();
163
- else
164
- (()@trusted { (d.ptr + cl)[0 .. len] = e[0 .. len]; })();
165
- }
166
- else
167
- {
168
- foreach (ref e; range)
169
- emplaceRef! (Unqual! T)(d[cl++ ], e);
170
- assert (_currentLength == cl);
171
- }
143
+ foreach (ref e; range)
144
+ emplaceRef! (Unqual! T)(d[cl++ ], e);
145
+ assert (_currentLength == cl);
172
146
}
173
147
else
174
148
{
0 commit comments