From 9ff77fe6ebc0512c5dff3e55b09ddfabdf664075 Mon Sep 17 00:00:00 2001 From: "H. S. Teoh" Date: Fri, 14 Jul 2017 10:47:05 -0700 Subject: [PATCH] Refactor joiner to reduce symbol bloat. Using Steven Schveighoffer's "horcrux" trick. In my range-heavy project, this single change resulted in a 50% reduction in executable size(!). --- std/algorithm/iteration.d | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/std/algorithm/iteration.d b/std/algorithm/iteration.d index 74eba6c3447..134248b0ee3 100644 --- a/std/algorithm/iteration.d +++ b/std/algorithm/iteration.d @@ -2406,10 +2406,15 @@ if (isInputRange!RoR && isInputRange!(ElementType!RoR) } /// Ditto -auto joiner(RoR)(RoR r) +template joiner(RoR) if (isInputRange!RoR && isInputRange!(ElementType!RoR)) { - static struct Result + auto joiner(RoR r) + { + return Result(r); + } + + struct Result { private: RoR _items; @@ -2509,7 +2514,6 @@ if (isInputRange!RoR && isInputRange!(ElementType!RoR)) } } } - return Result(r); } @safe unittest