From 2d3df68333c0f30efa117548f64357dd0b8fe660 Mon Sep 17 00:00:00 2001 From: drug007 Date: Thu, 20 Sep 2018 10:32:25 +0300 Subject: [PATCH] String literal reduces memory allocation. `-profile=gc` showed that `assert` allocated memory for every iteration. --- source/taggedalgebraic.d | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/taggedalgebraic.d b/source/taggedalgebraic.d index e862e3d..5bc2a44 100644 --- a/source/taggedalgebraic.d +++ b/source/taggedalgebraic.d @@ -941,7 +941,8 @@ private static auto implementOp(OpKind kind, string name, T, ARGS...)(ref T self //import std.meta : staticMap; pragma(msg, staticMap!(isMatchingUniqueType!(T.Union), info.ReturnTypes)); switch (self.m_kind) { - default: assert(false, "Operator "~name~" ("~kind.stringof~") can only be used on values of the following types: "~[info.fields].join(", ")); + enum assert_msg = "Operator "~name~" ("~kind.stringof~") can only be used on values of the following types: "~[info.fields].join(", "); + default: assert(false, assert_msg); foreach (i, f; info.fields) { alias FT = typeof(__traits(getMember, T.Union, f)); case __traits(getMember, T.Kind, f):