Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #669 from yebblies/issue10318
Browse files Browse the repository at this point in the history
Do not use sort property directly
  • Loading branch information
WalterBright committed Sep 25, 2014
2 parents f5d542b + b9f8421 commit ec670e5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
7 changes: 3 additions & 4 deletions src/object_.d
Original file line number Diff line number Diff line change
Expand Up @@ -2135,10 +2135,9 @@ pure /*nothrow @@@BUG5555@@@*/ unittest
}

assert(c.length == 3);
c.sort;
assert(c[0] == 1);
assert(c[1] == 2);
assert(c[2] == 3);
assert(c[0] == 1 || c[1] == 1 || c[2] == 1);
assert(c[0] == 2 || c[1] == 2 || c[2] == 2);
assert(c[0] == 3 || c[1] == 3 || c[2] == 3);
}

pure nothrow unittest
Expand Down
28 changes: 15 additions & 13 deletions src/rt/adi.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private
import core.stdc.stdlib;
import core.memory;
import rt.util.utf;

extern (C) void[] _adSort(void[] a, TypeInfo ti);
}


Expand Down Expand Up @@ -98,24 +100,24 @@ unittest
{
auto a = "abcd"c[];

auto r = a.dup.reverse;
auto r = _adReverseChar(a.dup);
//writefln(r);
assert(r == "dcba");

a = "a\u1235\u1234c";
//writefln(a);
r = a.dup.reverse;
r = _adReverseChar(a.dup);
//writefln(r);
assert(r == "c\u1234\u1235a");

a = "ab\u1234c";
//writefln(a);
r = a.dup.reverse;
r = _adReverseChar(a.dup);
//writefln(r);
assert(r == "c\u1234ba");

a = "\u3026\u2021\u3061\n";
r = a.dup.reverse;
r = _adReverseChar(a.dup);
assert(r == "\n\u3061\u2021\u3026");
}

Expand Down Expand Up @@ -194,23 +196,23 @@ unittest
{
wstring a = "abcd";

auto r = a.dup.reverse;
auto r = _adReverseWchar(a.dup);
assert(r == "dcba");

a = "a\U00012356\U00012346c";
r = a.dup.reverse;
r = _adReverseWchar(a.dup);
assert(r == "c\U00012346\U00012356a");

a = "ab\U00012345c";
r = a.dup.reverse;
r = _adReverseWchar(a.dup);
assert(r == "c\U00012345ba");
}
{
wstring a = "a\U00000081b\U00002000c\U00010000";
wchar[] b = a.dup;

b.reverse;
b.reverse;
_adReverseWchar(b);
_adReverseWchar(b);
assert(b == "a\U00000081b\U00002000c\U00010000");
}
}
Expand Down Expand Up @@ -274,7 +276,7 @@ unittest

for (auto i = 0; i < 5; i++)
a[i] = i;
b = a.reverse;
*(cast(void[]*)&b) = _adReverse(*cast(void[]*)&a, a[0].sizeof);
assert(b is a);
for (auto i = 0; i < 5; i++)
assert(a[i] == 4 - i);
Expand All @@ -292,7 +294,7 @@ unittest
{ c[i].a = i;
c[i].e = 10;
}
d = c.reverse;
*(cast(void[]*)&d) = _adReverse(*(cast(void[]*)&c), c[0].sizeof);
assert(d is c);
for (auto i = 0; i < 5; i++)
{
Expand Down Expand Up @@ -327,7 +329,7 @@ extern (C) char[] _adSortChar(char[] a)
if (a.length > 1)
{
auto da = mallocUTF32(a);
da.sort;
_adSort(*cast(void[]*)&da, typeid(da[0]));
size_t i = 0;
foreach (dchar d; da)
{ char[4] buf;
Expand All @@ -349,7 +351,7 @@ extern (C) wchar[] _adSortWchar(wchar[] a)
if (a.length > 1)
{
auto da = mallocUTF32(a);
da.sort;
_adSort(*cast(void[]*)&da, typeid(da[0]));
size_t i = 0;
foreach (dchar d; da)
{ wchar[2] buf;
Expand Down
2 changes: 1 addition & 1 deletion src/rt/qsort.d
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ unittest
a[8] = 0;
a[9] = -1;

a.sort;
_adSort(*cast(void[]*)&a, typeid(a[0]));

for (int i = 0; i < a.length - 1; i++)
{
Expand Down
6 changes: 4 additions & 2 deletions src/rt/typeinfo/ti_Aint.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module rt.typeinfo.ti_Aint;
private import core.stdc.string;
private import rt.util.hash;

extern (C) void[] _adSort(void[] a, TypeInfo ti);

// int[]

class TypeInfo_Ai : TypeInfo_Array
Expand Down Expand Up @@ -70,11 +72,11 @@ class TypeInfo_Ai : TypeInfo_Array
unittest
{
int[][] a = [[5,3,8,7], [2,5,3,8,7]];
a.sort;
_adSort(*cast(void[]*)&a, typeid(a[0]));
assert(a == [[2,5,3,8,7], [5,3,8,7]]);

a = [[5,3,8,7], [5,3,8]];
a.sort;
_adSort(*cast(void[]*)&a, typeid(a[0]));
assert(a == [[5,3,8], [5,3,8,7]]);
}

Expand Down

0 comments on commit ec670e5

Please sign in to comment.