Skip to content

Commit d13e80f

Browse files
committed
Express reserve() using prepare()
1 parent b486406 commit d13e80f

File tree

1 file changed

+3
-38
lines changed

1 file changed

+3
-38
lines changed

source/mir/appender.d

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,45 +39,10 @@ struct ScopedBuffer(T, size_t bytes = 4096)
3939
}
4040

4141
///
42-
void reserve(size_t n) @trusted scope
42+
void reserve(size_t n) @safe scope
4343
{
44-
import mir.internal.memory: realloc, malloc;
45-
const nextLength = _currentLength + n;
46-
if (_buffer.length == 0)
47-
{
48-
if (nextLength <= _bufferLength)
49-
{
50-
return;
51-
}
52-
else
53-
{
54-
const newLen = nextLength << 1;
55-
if (auto p = malloc(T.sizeof * newLen))
56-
{
57-
_buffer = (cast(T*)p)[0 .. newLen];
58-
}
59-
else assert(0);
60-
version (mir_secure_memory)
61-
{
62-
(cast(ubyte[])_buffer)[] = 0;
63-
}
64-
memcpy(cast(void*)_buffer.ptr, _scopeBuffer.ptr, T.sizeof * (nextLength - n));
65-
}
66-
}
67-
else
68-
if (nextLength > _buffer.length)
69-
{
70-
const newLen = nextLength << 1;
71-
if (auto p = realloc(cast(void*)_buffer.ptr, T.sizeof * newLen))
72-
{
73-
_buffer = (cast(T*)p)[0 .. newLen];
74-
}
75-
else assert(0);
76-
version (mir_secure_memory)
77-
{
78-
(cast(ubyte[])_buffer[nextLength .. $])[] = 0;
79-
}
80-
}
44+
prepare(n);
45+
_currentLength -= n;
8146
}
8247

8348
///

0 commit comments

Comments
 (0)