Skip to content

Commit 428eb01

Browse files
committed
add trusted assign to small_string and small_array
1 parent ec9bf53 commit 428eb01

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

source/mir/small_array.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ struct SmallArray(T, uint maxLength)
169169
return this;
170170
}
171171

172+
///
173+
void trustedAssign(V[] array) @trusted
174+
{
175+
_data[0 .. _length] = T.init;
176+
_length = cast(uint) array.length;
177+
_data[0 .. _length] = array;
178+
}
179+
172180
///
173181
ref typeof(this) append(T elem)
174182
{

source/mir/small_string.d

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ extern(D):
179179
return this;
180180
}
181181

182+
/// ditto
183+
void trustedAssign(scope const(char)[] str) return @trusted nothrow
184+
{
185+
_data = '\0';
186+
if (__ctfe)
187+
(cast(char[])_data)[0 .. str.length] = cast(char[]) str;
188+
else
189+
memcpy(_data.ptr, str.ptr, str.length);
190+
}
191+
182192
///
183193
ref typeof(this) append(char c) @trusted
184194
{

0 commit comments

Comments
 (0)