Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/object.di
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ template _isStaticArray(T)

private
{
extern (C) void _d_arrayshrinkfit(TypeInfo ti, void[] arr);
extern (C) void _d_arrayshrinkfit(TypeInfo ti, void[] arr) pure nothrow;
extern (C) size_t _d_arraysetcapacity(TypeInfo ti, size_t newcapacity, void *arrptr) pure nothrow;
}

Expand All @@ -550,7 +550,7 @@ size_t reserve(T)(ref T[] arr, size_t newcapacity) pure nothrow @trusted
return _d_arraysetcapacity(typeid(T[]), newcapacity, cast(void *)&arr);
}

auto ref inout(T[]) assumeSafeAppend(T)(auto ref inout(T[]) arr)
auto ref inout(T[]) assumeSafeAppend(T)(auto ref inout(T[]) arr) pure nothrow
{
_d_arrayshrinkfit(typeid(T[]), *(cast(void[]*)&arr));
return arr;
Expand Down
4 changes: 2 additions & 2 deletions src/object_.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private

extern (C) void onOutOfMemoryError() @trusted /* pure dmd @@@BUG11461@@@ */ nothrow;
extern (C) Object _d_newclass(const TypeInfo_Class ci);
extern (C) void _d_arrayshrinkfit(const TypeInfo ti, void[] arr);
extern (C) void _d_arrayshrinkfit(const TypeInfo ti, void[] arr) pure nothrow;
extern (C) size_t _d_arraysetcapacity(const TypeInfo ti, size_t newcapacity, void *arrptr) pure nothrow;
extern (C) void rt_finalize(void *data, bool det=true);
}
Expand Down Expand Up @@ -2522,7 +2522,7 @@ unittest
* Returns:
* The input is returned.
*/
auto ref inout(T[]) assumeSafeAppend(T)(auto ref inout(T[]) arr)
auto ref inout(T[]) assumeSafeAppend(T)(auto ref inout(T[]) arr) pure nothrow
{
_d_arrayshrinkfit(typeid(T[]), *(cast(void[]*)&arr));
return arr;
Expand Down
5 changes: 4 additions & 1 deletion src/rt/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ void __insertBlkInfoCache(BlkInfo bi, BlkInfo *curpos) nothrow
* It doesn't matter what the current allocated length of the array is, the
* user is telling the runtime that he knows what he is doing.
*/
extern(C) void _d_arrayshrinkfit(const TypeInfo ti, void[] arr)
extern(C) void _d_arrayshrinkfit(const TypeInfo ti, void[] arr) /+nothrow+/
{
// note, we do not care about shared. We are setting the length no matter
// what, so no lock is required.
Expand All @@ -563,6 +563,9 @@ extern(C) void _d_arrayshrinkfit(const TypeInfo ti, void[] arr)
// remove prefix from the current stored size
cursize -= LARGEPREFIX;
debug(PRINTF) printf("setting allocated size to %d\n", (arr.ptr - info.base) + cursize);

// Note: Since we "assume" the append is safe, it means it is not shared.
// Since it is not shared, we also know it won't throw (no lock).
__setArrayAllocLength(info, (arr.ptr - info.base) + cursize, false);
}
}
Expand Down