From 0090ae5cf2887720cd18746eda71c06e4406d34f Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 14 May 2018 15:48:57 +0200 Subject: [PATCH] Optimization in CheckUninitVar::checkStruct(): Replaced expensive inner loop on all scopes by loop on child scopes for faster lookup for inner unions. This speeds up checking of very large code files; for example, it reduces checking time for SQLite amalgamation by more than 20% --- lib/checkuninitvar.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 477f3a5f9..08d47fd11 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -175,15 +175,14 @@ void CheckUninitVar::checkStruct(const Token *tok, const Variable &structvar) // is the variable declared in a inner union? bool innerunion = false; - for (std::list::const_iterator it2 = symbolDatabase->scopeList.begin(); it2 != symbolDatabase->scopeList.end(); ++it2) { - const Scope &innerScope = *it2; - if (innerScope.type == Scope::eUnion && innerScope.nestedIn == scope2) { + for (auto it2 = scope2->nestedList.cbegin(); it2 != scope2->nestedList.cend(); ++it2) { + const Scope &innerScope = **it2; + if (innerScope.type == Scope::eUnion) { if (var.typeStartToken()->linenr() >= innerScope.bodyStart->linenr() && var.typeStartToken()->linenr() <= innerScope.bodyEnd->linenr()) { innerunion = true; break; } - } }