C++: Minor optimization

Avoid double map lookup

Change-Id: I5fe6b4a13829275f5a68f794cb820b488f4a5c8c
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-05-22 10:58:41 +03:00
committed by Nikolai Kosjar
parent 36f83ba99a
commit 04c4043e13

View File

@@ -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)