Commit 04c4043e authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Nikolai Kosjar
Browse files

C++: Minor optimization



Avoid double map lookup

Change-Id: I5fe6b4a13829275f5a68f794cb820b488f4a5c8c
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 36f83ba9
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment