Skip to content

std.array.d: Use template `_d_newarrayU{,Trace} #10819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
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
19 changes: 6 additions & 13 deletions std/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -1073,14 +1073,6 @@ if (isDynamicArray!T && allSatisfy!(isIntegral, I))
}
}

// from rt/lifetime.d
private extern(C) void[] _d_newarrayU(const TypeInfo ti, size_t length) pure nothrow;

// from rt/tracegc.d
version (D_ProfileGC)
private extern (C) void[] _d_newarrayUTrace(string file, size_t line,
string funcname, const scope TypeInfo ti, size_t length) pure nothrow;

private auto arrayAllocImpl(bool minimallyInitialized, T, I...)(I sizes) nothrow
{
static assert(I.length <= nDimensions!T,
Expand Down Expand Up @@ -1131,18 +1123,19 @@ private auto arrayAllocImpl(bool minimallyInitialized, T, I...)(I sizes) nothrow
which will inform the GC how to destroy the items in the block
when it gets collected.

_d_newarrayU returns a void[], but with the length set according
to E.sizeof.
_d_newarrayU returns a E[], with the length set according to
to the size parameter.
+/
enum isShared = is (E == shared);
version (D_ProfileGC)
{
// FIXME: file, line, function should be propagated from the
// caller, not here.
*(cast(void[]*)&ret) = _d_newarrayUTrace(__FILE__, __LINE__,
__FUNCTION__, typeid(E[]), size);
ret = _d_newarrayUTrace!E(size, isShared,
__FILE__, __LINE__, __FUNCTION__);
}
else
*(cast(void[]*)&ret) = _d_newarrayU(typeid(E[]), size);
ret = _d_newarrayU!E(size, isShared);
static if (minimallyInitialized && hasIndirections!E)
// _d_newarrayU would have asserted if the multiplication below
// had overflowed, so we don't have to check it again.
Expand Down
Loading