dastworx, lazy init the badVersions and use AA for lookup

This commit is contained in:
Basile Burg 2016-08-05 22:26:56 +02:00
parent bcd374526f
commit 4a41db237a
3 changed files with 13 additions and 10 deletions

View File

@ -50,11 +50,19 @@ q{
else version(unittest) log(); else version(unittest) log();
}; };
/** /**
* Contains all the D version identifiers that are not valid * Contains all the D version identifiers that are not valid
* for this operating system. * for this operating system.
*/ */
immutable string[] badVersions; ref const(bool[string]) badVersions()
{
if (!_badVersions.length)
fillBadVersions;
return _badVersions;
}
private __gshared bool[string] _badVersions;
private static immutable predefinedVersions = [ private static immutable predefinedVersions = [
"AArch64", "AArch64",
@ -154,12 +162,12 @@ private static immutable predefinedVersions = [
"X86_64" "X86_64"
]; ];
static this() private void fillBadVersions()
{ {
// note: compiler switch -m32/64 can lead to wrong results // note: compiler switch -m32/64 can lead to wrong results
string addVersionidentifier(string ver)() string addVersionidentifier(string ver)()
{ {
return `version(` ~ ver ~ `){} else badVersions ~= "` ~ ver ~ "\";\n"; return `version(` ~ ver ~ `){} else _badVersions["` ~ ver ~ "\"] = true;\n";
} }
string addVerionIdentifiers() string addVerionIdentifiers()

View File

@ -75,7 +75,7 @@ private final class ImportLister: ASTVisitor
override void visit(const ConditionalDeclaration decl) override void visit(const ConditionalDeclaration decl)
{ {
const VersionCondition ver = decl.compileCondition.versionCondition; const VersionCondition ver = decl.compileCondition.versionCondition;
if (ver is null || !canFind(badVersions, ver.token.text)) if (ver is null || ver.token.text !in badVersions)
decl.accept(this); decl.accept(this);
} }

View File

@ -34,15 +34,10 @@ private final class MainFunctionDetector: ASTVisitor
ubyte hasMain; ubyte hasMain;
this()
{
hasMain = false;
}
override void visit(const ConditionalDeclaration decl) override void visit(const ConditionalDeclaration decl)
{ {
const VersionCondition ver = decl.compileCondition.versionCondition; const VersionCondition ver = decl.compileCondition.versionCondition;
if (ver is null || !canFind(badVersions, ver.token.text)) if (ver is null || ver.token.text !in badVersions)
decl.accept(this); decl.accept(this);
} }