Skip to content

Commit e069741

Browse files
VPanteleev-S7schveiguy
authored andcommitted
std.typecons: Make Nullable.toString always a template (dlang#10767)
Because some overloads of Nullable!T.toString are not templates, instantiating a Nullable!T also always instantiates formatValue!T, and all of its dependencies. For large type hierarchies, this can add a significant amount of compilation overhead. We can avoid this by making remaining overloads of Nullable!T.toString templates as well, similar to Tuple. Timings from internal motivating use case: Before: 9.00user 1.38system 0:10.57elapsed 98%CPU (0avgtext+0avgdata 5851516maxresident)k 21968inputs+48144outputs (0major+1468687minor)pagefaults 0swaps After: 5.11user 0.61system 0:05.75elapsed 99%CPU (0avgtext+0avgdata 2762392maxresident)k 0inputs+34528outputs (0major+685900minor)pagefaults 0swaps
1 parent b438663 commit e069741

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

std/typecons.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3836,22 +3836,22 @@ struct Nullable(T)
38363836
* Returns:
38373837
* A `string` if `writer` and `fmt` are not set; `void` otherwise.
38383838
*/
3839-
string toString()
3839+
string toString()()
38403840
{
38413841
import std.array : appender;
38423842
auto app = appender!string();
38433843
auto spec = singleSpec("%s");
3844-
toString(app, spec);
3844+
this.toString(app, spec);
38453845
return app.data;
38463846
}
38473847

38483848
/// ditto
3849-
string toString() const
3849+
string toString()() const
38503850
{
38513851
import std.array : appender;
38523852
auto app = appender!string();
38533853
auto spec = singleSpec("%s");
3854-
toString(app, spec);
3854+
this.toString(app, spec);
38553855
return app.data;
38563856
}
38573857

0 commit comments

Comments
 (0)