From 4a41db237a830f7b35cd34a302b8e68feaa861af Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Fri, 5 Aug 2016 22:26:56 +0200 Subject: [PATCH] dastworx, lazy init the badVersions and use AA for lookup --- dastworx/src/common.d | 14 +++++++++++--- dastworx/src/imports.d | 2 +- dastworx/src/mainfun.d | 7 +------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dastworx/src/common.d b/dastworx/src/common.d index 478208f9..e438f771 100644 --- a/dastworx/src/common.d +++ b/dastworx/src/common.d @@ -50,11 +50,19 @@ q{ else version(unittest) log(); }; + /** * Contains all the D version identifiers that are not valid * 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 = [ "AArch64", @@ -154,12 +162,12 @@ private static immutable predefinedVersions = [ "X86_64" ]; -static this() +private void fillBadVersions() { // note: compiler switch -m32/64 can lead to wrong results string addVersionidentifier(string ver)() { - return `version(` ~ ver ~ `){} else badVersions ~= "` ~ ver ~ "\";\n"; + return `version(` ~ ver ~ `){} else _badVersions["` ~ ver ~ "\"] = true;\n"; } string addVerionIdentifiers() diff --git a/dastworx/src/imports.d b/dastworx/src/imports.d index 2cbcab6c..aa308828 100644 --- a/dastworx/src/imports.d +++ b/dastworx/src/imports.d @@ -75,7 +75,7 @@ private final class ImportLister: ASTVisitor override void visit(const ConditionalDeclaration decl) { 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); } diff --git a/dastworx/src/mainfun.d b/dastworx/src/mainfun.d index 8bd5da38..7e988eb8 100644 --- a/dastworx/src/mainfun.d +++ b/dastworx/src/mainfun.d @@ -34,15 +34,10 @@ private final class MainFunctionDetector: ASTVisitor ubyte hasMain; - this() - { - hasMain = false; - } - override void visit(const ConditionalDeclaration decl) { 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); }