From 7bd3dc5da62a5468c204f8b71dc0fe9cca9b1dd4 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Mon, 28 Aug 2017 18:19:03 +0300 Subject: [PATCH] Simplify array access with references --- lib/library.cpp | 5 +++-- lib/symboldatabase.cpp | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/library.cpp b/lib/library.cpp index 2a5e685bd..a7286a022 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -743,8 +743,9 @@ std::string Library::getFunctionName(const Token *ftok, bool *error) const for (const Scope *scope = ftok->scope(); scope; scope = scope->nestedIn) { if (!scope->isClassOrStruct()) continue; - for (unsigned int i = 0; i < scope->definedType->derivedFrom.size(); ++i) { - const Type::BaseInfo &baseInfo = scope->definedType->derivedFrom[i]; + const std::vector &derivedFrom = scope->definedType->derivedFrom; + for (unsigned int i = 0; i < derivedFrom.size(); ++i) { + const Type::BaseInfo &baseInfo = derivedFrom[i]; const std::string name(baseInfo.name + "::" + ftok->str()); if (functions.find(name) != functions.end() && matchArguments(ftok, name)) return name; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index b5bbbccbb..de4edaafb 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3680,9 +3680,11 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok) const } if (scope->definedType) { - for (size_t i = 0, end = scope->definedType->derivedFrom.size(); i < end; ++i) { - if (scope->definedType->derivedFrom[i].type && scope->definedType->derivedFrom[i].type->classScope) { - enumerator = scope->definedType->derivedFrom[i].type->classScope->findEnumerator(tok->str()); + const std::vector & derivedFrom = scope->definedType->derivedFrom; + for (size_t i = 0, end = derivedFrom.size(); i < end; ++i) { + const Type *derivedFromType = derivedFrom[i].type; + if (derivedFromType && derivedFromType ->classScope) { + enumerator = derivedFromType->classScope->findEnumerator(tok->str()); if (enumerator) return enumerator;