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

Commit 1876c9b

Browse files
authored
Merge pull request #3118 from n8sh/backport-phobos-7490
Port more efficient Filter & staticMap from dlang/phobos#7490 merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2 parents 5e37bce + d78bcf0 commit 1876c9b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/core/internal/traits.d

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,26 @@ template Filter(alias pred, TList...)
466466
else
467467
alias Filter = AliasSeq!();
468468
}
469+
/* The next case speeds up compilation by reducing
470+
* the number of Filter instantiations
471+
*/
472+
else static if (TList.length == 2)
473+
{
474+
static if (pred!(TList[0]))
475+
{
476+
static if (pred!(TList[1]))
477+
alias Filter = AliasSeq!(TList[0], TList[1]);
478+
else
479+
alias Filter = AliasSeq!(TList[0]);
480+
}
481+
else
482+
{
483+
static if (pred!(TList[1]))
484+
alias Filter = AliasSeq!(TList[1]);
485+
else
486+
alias Filter = AliasSeq!();
487+
}
488+
}
469489
else
470490
{
471491
alias Filter =
@@ -486,6 +506,37 @@ template staticMap(alias F, T...)
486506
{
487507
alias staticMap = AliasSeq!(F!(T[0]));
488508
}
509+
/* Cases 2 to 8 improve compile performance by reducing
510+
* the number of recursive instantiations of staticMap
511+
*/
512+
else static if (T.length == 2)
513+
{
514+
alias staticMap = AliasSeq!(F!(T[0]), F!(T[1]));
515+
}
516+
else static if (T.length == 3)
517+
{
518+
alias staticMap = AliasSeq!(F!(T[0]), F!(T[1]), F!(T[2]));
519+
}
520+
else static if (T.length == 4)
521+
{
522+
alias staticMap = AliasSeq!(F!(T[0]), F!(T[1]), F!(T[2]), F!(T[3]));
523+
}
524+
else static if (T.length == 5)
525+
{
526+
alias staticMap = AliasSeq!(F!(T[0]), F!(T[1]), F!(T[2]), F!(T[3]), F!(T[4]));
527+
}
528+
else static if (T.length == 6)
529+
{
530+
alias staticMap = AliasSeq!(F!(T[0]), F!(T[1]), F!(T[2]), F!(T[3]), F!(T[4]), F!(T[5]));
531+
}
532+
else static if (T.length == 7)
533+
{
534+
alias staticMap = AliasSeq!(F!(T[0]), F!(T[1]), F!(T[2]), F!(T[3]), F!(T[4]), F!(T[5]), F!(T[6]));
535+
}
536+
else static if (T.length == 8)
537+
{
538+
alias staticMap = AliasSeq!(F!(T[0]), F!(T[1]), F!(T[2]), F!(T[3]), F!(T[4]), F!(T[5]), F!(T[6]), F!(T[7]));
539+
}
489540
else
490541
{
491542
alias staticMap =

0 commit comments

Comments
 (0)