mirror of
https://github.com/dlang/phobos.git
synced 2025-05-05 01:20:40 +03:00
Tighter loop for insertion sorting
This commit is contained in:
parent
97f58eac9d
commit
a4393248ba
1 changed files with 7 additions and 6 deletions
|
@ -1326,16 +1326,17 @@ private void shortSort(alias less, Range)(Range r)
|
|||
auto t = r[0]; if (pred(t, r[0])) r[0] = r[0];
|
||||
}))) // Can we afford to temporarily invalidate the array?
|
||||
{
|
||||
size_t j = i;
|
||||
if (pred(r[j + 1], r[j]))
|
||||
size_t j = i + 1;
|
||||
auto temp = r[i];
|
||||
if (pred(r[j], temp))
|
||||
{
|
||||
auto temp = r[j];
|
||||
do
|
||||
{
|
||||
r[j] = r[j + 1];
|
||||
r[j - 1] = r[j];
|
||||
++j;
|
||||
}
|
||||
while (++j + 1 < r.length && pred(r[j + 1], temp));
|
||||
r[j] = temp;
|
||||
while (j < r.length && pred(r[j], temp));
|
||||
r[j - 1] = temp;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue