Remove Init template parameter from memory.resize()

This commit is contained in:
2017-03-22 08:51:00 +01:00
parent b90517580e
commit 7892c1a930
2 changed files with 18 additions and 27 deletions

View File

@ -137,7 +137,8 @@ template stateSize(T)
*
* Returns: Aligned size.
*/
size_t alignedSize(in size_t size, in size_t alignment = 8) pure nothrow @safe @nogc
size_t alignedSize(const size_t size, const size_t alignment = 8)
pure nothrow @safe @nogc
{
return (size - 1) / alignment * alignment + alignment;
}
@ -145,31 +146,24 @@ size_t alignedSize(in size_t size, in size_t alignment = 8) pure nothrow @safe @
/**
* Internal function used to create, resize or destroy a dynamic array. It
* may throw $(D_PSYMBOL OutOfMemoryError). The new
* allocated part of the array is initialized only if $(D_PARAM Init)
* is set. This function can be trusted only in the data structures that
* can ensure that the array is allocated/rellocated/deallocated with the
* same allocator.
* allocated part of the array isn't initialized. This function can be trusted
* only in the data structures that can ensure that the array is
* allocated/rellocated/deallocated with the same allocator.
*
* Params:
* T = Element type of the array being created.
* Init = If should be initialized.
* allocator = The allocator used for getting memory.
* array = A reference to the array being changed.
* length = New array length.
*
* Returns: $(D_PARAM array).
*/
package(tanya) T[] resize(T,
bool Init = true)
(shared Allocator allocator,
auto ref T[] array,
const size_t length) @trusted
package(tanya) T[] resize(T)(shared Allocator allocator,
auto ref T[] array,
const size_t length) @trusted
{
void[] buf = array;
static if (Init)
{
const oldLength = array.length;
}
if (!allocator.reallocate(buf, length * T.sizeof))
{
onOutOfMemoryError;
@ -177,13 +171,6 @@ package(tanya) T[] resize(T,
// Casting from void[] is unsafe, but we know we cast to the original type.
array = cast(T[]) buf;
static if (Init)
{
if (oldLength < length)
{
array[oldLength .. $] = T.init;
}
}
return array;
}