mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 22:50:38 +03:00
Make ensureAddable and callers infer function attributes
This commit is contained in:
parent
c575e985b3
commit
fa19e3f5e7
1 changed files with 8 additions and 8 deletions
16
std/array.d
16
std/array.d
|
@ -3018,7 +3018,7 @@ if (isDynamicArray!A)
|
||||||
* Params:
|
* Params:
|
||||||
* newCapacity = the capacity the `Appender` should have
|
* newCapacity = the capacity the `Appender` should have
|
||||||
*/
|
*/
|
||||||
void reserve(size_t newCapacity) @safe nothrow
|
void reserve(size_t newCapacity)
|
||||||
{
|
{
|
||||||
if (_data)
|
if (_data)
|
||||||
{
|
{
|
||||||
|
@ -3053,7 +3053,7 @@ if (isDynamicArray!A)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure we can add nelems elements, resizing as necessary
|
// ensure we can add nelems elements, resizing as necessary
|
||||||
private void ensureAddable(size_t nelems) @trusted nothrow
|
private void ensureAddable(size_t nelems)
|
||||||
{
|
{
|
||||||
if (!_data)
|
if (!_data)
|
||||||
_data = new Data;
|
_data = new Data;
|
||||||
|
@ -3089,7 +3089,7 @@ if (isDynamicArray!A)
|
||||||
// first, try extending the current block
|
// first, try extending the current block
|
||||||
if (_data.canExtend)
|
if (_data.canExtend)
|
||||||
{
|
{
|
||||||
immutable u = GC.extend(_data.arr.ptr, nelems * T.sizeof, (newlen - len) * T.sizeof);
|
immutable u = (() @trusted => GC.extend(_data.arr.ptr, nelems * T.sizeof, (newlen - len) * T.sizeof))();
|
||||||
if (u)
|
if (u)
|
||||||
{
|
{
|
||||||
// extend worked, update the capacity
|
// extend worked, update the capacity
|
||||||
|
@ -3105,12 +3105,12 @@ if (isDynamicArray!A)
|
||||||
const nbytes = mulu(newlen, T.sizeof, overflow);
|
const nbytes = mulu(newlen, T.sizeof, overflow);
|
||||||
if (overflow) assert(0);
|
if (overflow) assert(0);
|
||||||
|
|
||||||
auto bi = GC.qalloc(nbytes, blockAttribute!T);
|
auto bi = (() @trusted => GC.qalloc(nbytes, blockAttribute!T))();
|
||||||
_data.capacity = bi.size / T.sizeof;
|
_data.capacity = bi.size / T.sizeof;
|
||||||
import core.stdc.string : memcpy;
|
import core.stdc.string : memcpy;
|
||||||
if (len)
|
if (len)
|
||||||
memcpy(bi.base, _data.arr.ptr, len * T.sizeof);
|
() @trusted { memcpy(bi.base, _data.arr.ptr, len * T.sizeof); }();
|
||||||
_data.arr = (cast(Unqual!T*) bi.base)[0 .. len];
|
_data.arr = (() @trusted => (cast(Unqual!T*) bi.base)[0 .. len])();
|
||||||
_data.canExtend = true;
|
_data.canExtend = true;
|
||||||
// leave the old data, for safety reasons
|
// leave the old data, for safety reasons
|
||||||
}
|
}
|
||||||
|
@ -3205,10 +3205,10 @@ if (isDynamicArray!A)
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure we have enough space, then add the items
|
// make sure we have enough space, then add the items
|
||||||
@trusted auto bigDataFun(size_t extra)
|
auto bigDataFun(size_t extra)
|
||||||
{
|
{
|
||||||
ensureAddable(extra);
|
ensureAddable(extra);
|
||||||
return _data.arr.ptr[0 .. _data.arr.length + extra];
|
return (() @trusted => _data.arr.ptr[0 .. _data.arr.length + extra])();
|
||||||
}
|
}
|
||||||
auto bigData = bigDataFun(items.length);
|
auto bigData = bigDataFun(items.length);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue