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%
This commit is contained in:
PKEuS 2018-05-14 15:48:57 +02:00
parent c4b6beac4d
commit 0090ae5cf2
1 changed files with 3 additions and 4 deletions

View File

@ -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<Scope>::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;
}
}
}