From ee612de84f3886762fc1a6eb23f390c38c4fb8bb Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Mon, 8 Jan 2018 17:13:23 +0100 Subject: [PATCH] Use a switch instead of a global dictionary for primitiveTypeInfo --- std/format.d | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/std/format.d b/std/format.d index 92b4048e4..83e58675b 100644 --- a/std/format.d +++ b/std/format.d @@ -5425,37 +5425,23 @@ enum Mangle : char // routine could go away. private TypeInfo primitiveTypeInfo(Mangle m) { - // BUG: should fix this in static this() to avoid double checked locking bug - __gshared TypeInfo[Mangle] dic; - if (!dic.length) + enum types = [ + "void", "bool", "byte", "ubyte", + "short", "ushort", "int", "uint", "long", "ulong", + "float", "double", "real", + "char", "wchar", "dchar", + "ifloat", "idouble", "ireal", + "cfloat", "cdouble", "creal", + ]; + switch (m) { - dic = [ - Mangle.Tvoid : typeid(void), - Mangle.Tbool : typeid(bool), - Mangle.Tbyte : typeid(byte), - Mangle.Tubyte : typeid(ubyte), - Mangle.Tshort : typeid(short), - Mangle.Tushort : typeid(ushort), - Mangle.Tint : typeid(int), - Mangle.Tuint : typeid(uint), - Mangle.Tlong : typeid(long), - Mangle.Tulong : typeid(ulong), - Mangle.Tfloat : typeid(float), - Mangle.Tdouble : typeid(double), - Mangle.Treal : typeid(real), - Mangle.Tifloat : typeid(ifloat), - Mangle.Tidouble : typeid(idouble), - Mangle.Tireal : typeid(ireal), - Mangle.Tcfloat : typeid(cfloat), - Mangle.Tcdouble : typeid(cdouble), - Mangle.Tcreal : typeid(creal), - Mangle.Tchar : typeid(char), - Mangle.Twchar : typeid(wchar), - Mangle.Tdchar : typeid(dchar) - ]; + static foreach (type; types) + { + mixin("case Mangle.T"~type~": return typeid("~type~");"); + } + default: + return null; } - auto p = m in dic; - return p ? *p : null; } private bool needToSwapEndianess(Char)(const ref FormatSpec!Char f)