From 04c4043e13f1d83067a1e4bbee5880b37050e876 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh <orgad.shaneh@audiocodes.com> Date: Fri, 22 May 2015 10:58:41 +0300 Subject: [PATCH] C++: Minor optimization Avoid double map lookup Change-Id: I5fe6b4a13829275f5a68f794cb820b488f4a5c8c Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> --- src/libs/3rdparty/cplusplus/Templates.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libs/3rdparty/cplusplus/Templates.cpp b/src/libs/3rdparty/cplusplus/Templates.cpp index 9ebd95e232..3b8ae9a23f 100644 --- a/src/libs/3rdparty/cplusplus/Templates.cpp +++ b/src/libs/3rdparty/cplusplus/Templates.cpp @@ -40,8 +40,9 @@ CloneType::CloneType(Clone *clone) FullySpecifiedType CloneType::cloneType(const FullySpecifiedType &type, Subst *subst) { TypeSubstPair typeSubstPair = std::make_pair(type, subst); - if (_cache.find(typeSubstPair) != _cache.end()) - return _cache[typeSubstPair]; + auto it = _cache.find(typeSubstPair); + if (it != _cache.end()) + return it->second; std::swap(_subst, subst); FullySpecifiedType ty(type); @@ -186,10 +187,10 @@ Symbol *CloneSymbol::cloneSymbol(Symbol *symbol, Subst *subst) return 0; SymbolSubstPair symbolSubstPair = std::make_pair(symbol, subst); - if (_cache.find(symbolSubstPair) != _cache.end()) { - Symbol *cachedSymbol = _cache[symbolSubstPair]; - if (cachedSymbol->enclosingScope() == symbol->enclosingScope()) - return cachedSymbol; + auto it = _cache.find(symbolSubstPair); + if (it != _cache.end()) { + if (it->second->enclosingScope() == symbol->enclosingScope()) + return it->second; } Symbol *r = 0; @@ -410,8 +411,9 @@ const Name *CloneName::cloneName(const Name *name, Subst *subst) return 0; NameSubstPair nameSubstPair = std::make_pair(name, subst); - if (_cache.find(nameSubstPair) != _cache.end()) - return _cache[nameSubstPair]; + auto it = _cache.find(nameSubstPair); + if (it != _cache.end()) + return it->second; const Name *r = 0; std::swap(_subst, subst); @@ -545,7 +547,7 @@ Symbol *Clone::instantiate(Template *templ, const FullySpecifiedType *const args FullySpecifiedType Subst::apply(const Name *name) const { if (name) { - std::map<const Name *, FullySpecifiedType, Name::Compare>::const_iterator it = _map.find(name); + auto it = _map.find(name); if (it != _map.end()) return it->second; else if (_previous) -- GitLab