Merge remote-tracking branch 'upstream/stable' into merge_stable

This commit is contained in:
Martin Nowak 2020-05-11 19:29:12 +02:00
commit a7d8def71b
4 changed files with 26 additions and 28 deletions

View file

@ -3000,7 +3000,13 @@ if (isRandomAccessRange!R && hasLength!R && hasSwappableElements!R &&
bool overflow;
const nbytes = mulu(len, T.sizeof, overflow);
if (overflow) assert(false, "multiplication overflowed");
return (cast(T*) malloc(nbytes))[0 .. len];
T[] result = (cast(T*) malloc(nbytes))[0 .. len];
static if (hasIndirections!T)
{
import core.memory : GC;
GC.addRange(result.ptr, nbytes);
}
return result;
}
auto xform1 = trustedMalloc(r.length);
@ -3014,6 +3020,11 @@ if (isRandomAccessRange!R && hasLength!R && hasSwappableElements!R &&
static void trustedFree(T[] p) @trusted
{
import core.stdc.stdlib : free;
static if (hasIndirections!T)
{
import core.memory : GC;
GC.removeRange(p.ptr);
}
free(p.ptr);
}
trustedFree(xform1);
@ -3143,6 +3154,20 @@ if (isRandomAccessRange!R && hasLength!R && hasSwappableElements!R)
assert(isSorted!("a < b")(map!(entropy)(arr)));
}
// https://issues.dlang.org/show_bug.cgi?id=20799
@safe unittest
{
import std.range : iota, retro;
import std.array : array;
auto arr = 1_000_000.iota.retro.array;
arr.schwartzSort!(
n => new int(n),
(a, b) => *a < *b
);
assert(arr.isSorted());
}
// partialSort
/**
Reorders the random-access range `r` such that the range `r[0 .. mid]`