mirror of
https://github.com/dlang/phobos.git
synced 2025-05-02 08:00:48 +03:00
Use a switch instead of a global dictionary for primitiveTypeInfo
This commit is contained in:
parent
dfc5fae8f3
commit
ee612de84f
1 changed files with 15 additions and 29 deletions
44
std/format.d
44
std/format.d
|
@ -5425,37 +5425,23 @@ enum Mangle : char
|
||||||
// routine could go away.
|
// routine could go away.
|
||||||
private TypeInfo primitiveTypeInfo(Mangle m)
|
private TypeInfo primitiveTypeInfo(Mangle m)
|
||||||
{
|
{
|
||||||
// BUG: should fix this in static this() to avoid double checked locking bug
|
enum types = [
|
||||||
__gshared TypeInfo[Mangle] dic;
|
"void", "bool", "byte", "ubyte",
|
||||||
if (!dic.length)
|
"short", "ushort", "int", "uint", "long", "ulong",
|
||||||
|
"float", "double", "real",
|
||||||
|
"char", "wchar", "dchar",
|
||||||
|
"ifloat", "idouble", "ireal",
|
||||||
|
"cfloat", "cdouble", "creal",
|
||||||
|
];
|
||||||
|
switch (m)
|
||||||
{
|
{
|
||||||
dic = [
|
static foreach (type; types)
|
||||||
Mangle.Tvoid : typeid(void),
|
{
|
||||||
Mangle.Tbool : typeid(bool),
|
mixin("case Mangle.T"~type~": return typeid("~type~");");
|
||||||
Mangle.Tbyte : typeid(byte),
|
}
|
||||||
Mangle.Tubyte : typeid(ubyte),
|
default:
|
||||||
Mangle.Tshort : typeid(short),
|
return null;
|
||||||
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)
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
auto p = m in dic;
|
|
||||||
return p ? *p : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool needToSwapEndianess(Char)(const ref FormatSpec!Char f)
|
private bool needToSwapEndianess(Char)(const ref FormatSpec!Char f)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue