Refactoring, use range for loop

This commit is contained in:
Daniel Marjamäki 2018-06-23 15:58:44 +02:00
parent d811a07aa3
commit 911020f601
1 changed files with 12 additions and 11 deletions

View File

@ -1327,27 +1327,28 @@ static std::size_t estimateSize(const Type* type, const Settings* settings, cons
return 0; return 0;
std::size_t cumulatedSize = 0; std::size_t cumulatedSize = 0;
for (std::list<Variable>::const_iterator i = type->classScope->varlist.cbegin(); i != type->classScope->varlist.cend(); ++i) { for (const Variable&var : type->classScope->varlist) {
std::size_t size = 0; std::size_t size = 0;
if (i->isStatic()) if (var.isStatic())
continue; continue;
if (i->isPointer() || i->isReference()) if (var.isPointer() || var.isReference())
size = settings->sizeof_pointer; size = settings->sizeof_pointer;
else if (i->type() && i->type()->classScope) else if (var.type() && var.type()->classScope)
size = estimateSize(i->type(), settings, symbolDatabase, recursionDepth+1); size = estimateSize(var.type(), settings, symbolDatabase, recursionDepth+1);
else if (i->valueType()->type == ValueType::Type::CONTAINER) else if (var.valueType()->type == ValueType::Type::CONTAINER)
size = 3 * settings->sizeof_pointer; // Just guess size = 3 * settings->sizeof_pointer; // Just guess
else else
size = symbolDatabase->sizeOfType(i->typeStartToken()); size = symbolDatabase->sizeOfType(i->typeStartToken());
if (i->isArray()) if (var.isArray())
cumulatedSize += size*i->dimension(0); cumulatedSize += size * var.dimension(0);
else else
cumulatedSize += size; cumulatedSize += size;
} }
for (std::vector<Type::BaseInfo>::const_iterator i = type->derivedFrom.cbegin(); i != type->derivedFrom.cend(); ++i) for (const Type::BaseInfo &baseInfo : type->derivedFrom) {
if (i->type && i->type->classScope) if (baseInfo.type && baseInfo.type->classScope)
cumulatedSize += estimateSize(i->type, settings, symbolDatabase, recursionDepth+1); cumulatedSize += estimateSize(baseInfo.type, settings, symbolDatabase, recursionDepth+1);
}
return cumulatedSize; return cumulatedSize;
} }