Commit 3c740066 authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

avoid indexed access to elements of the value map stack



this makes us independent from the random access performance of the
underlying container.

Change-Id: I0e655320ad607ac43ef6797e52e6179570c155f4
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
Reviewed-by: default avatarOswald Buddenhagen <oswald.buddenhagen@nokia.com>
parent c17c479b
......@@ -82,7 +82,7 @@ QStringList ProFileEvaluator::values(const QString &variableName) const
QStringList ProFileEvaluator::values(const QString &variableName, const ProFile *pro) const
{
// It makes no sense to put any kind of magic into expanding these
const ProStringList &values = d->m_valuemapStack.at(0).value(ProKey(variableName));
const ProStringList &values = d->m_valuemapStack.first().value(ProKey(variableName));
QStringList ret;
ret.reserve(values.size());
foreach (const ProString &str, values)
......
......@@ -1089,18 +1089,19 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
return ReturnFalse;
}
const ProKey &var = map(args.at(0));
for (int i = m_valuemapStack.size(); --i > 0; ) {
ProValueMap::Iterator it = m_valuemapStack[i].find(var);
if (it != m_valuemapStack.at(i).end()) {
for (ProValueMapStack::Iterator vmi = m_valuemapStack.end();
--vmi != m_valuemapStack.begin(); ) {
ProValueMap::Iterator it = (*vmi).find(var);
if (it != (*vmi).end()) {
if (it->constBegin() == statics.fakeValue.constBegin()) {
// This is stupid, but qmake doesn't propagate deletions
m_valuemapStack[0][var] = ProStringList();
m_valuemapStack.first()[var] = ProStringList();
} else {
m_valuemapStack[0][var] = *it;
m_valuemapStack.first()[var] = *it;
}
m_valuemapStack[i].erase(it);
while (--i)
m_valuemapStack[i].remove(var);
(*vmi).erase(it);
while (--vmi != m_valuemapStack.begin())
(*vmi).remove(var);
break;
}
}
......
......@@ -1304,7 +1304,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProFile(
#ifdef QT_BUILD_QMAKE
for (ProValueMap::ConstIterator it = m_extraVars.constBegin();
it != m_extraVars.constEnd(); ++it)
m_valuemapStack[0].insert(it.key(), it.value());
m_valuemapStack.first().insert(it.key(), it.value());
#endif
m_handler->aboutToEval(currentProFile(), pro, type);
......@@ -1673,15 +1673,17 @@ void QMakeEvaluator::checkRequirements(const ProStringList &deps)
ProValueMap *QMakeEvaluator::findValues(const ProKey &variableName, ProValueMap::Iterator *rit)
{
for (int i = m_valuemapStack.size(); --i >= 0; ) {
ProValueMap::Iterator it = m_valuemapStack[i].find(variableName);
if (it != m_valuemapStack[i].end()) {
ProValueMapStack::Iterator vmi = m_valuemapStack.end();
do {
--vmi;
ProValueMap::Iterator it = (*vmi).find(variableName);
if (it != (*vmi).end()) {
if (it->constBegin() == statics.fakeValue.constBegin())
return 0;
*rit = it;
return &m_valuemapStack[i];
return &(*vmi);
}
}
} while (vmi != m_valuemapStack.begin());
return 0;
}
......@@ -1693,28 +1695,34 @@ ProStringList &QMakeEvaluator::valuesRef(const ProKey &variableName)
it->clear();
return *it;
}
for (int i = m_valuemapStack.size() - 1; --i >= 0; ) {
ProValueMap::ConstIterator it = m_valuemapStack.at(i).constFind(variableName);
if (it != m_valuemapStack.at(i).constEnd()) {
ProStringList &ret = m_valuemapStack.top()[variableName];
if (it->constBegin() != statics.fakeValue.constBegin())
ret = *it;
return ret;
}
ProValueMapStack::Iterator vmi = m_valuemapStack.end();
if (--vmi != m_valuemapStack.begin()) {
do {
--vmi;
ProValueMap::ConstIterator it = (*vmi).constFind(variableName);
if (it != (*vmi).constEnd()) {
ProStringList &ret = m_valuemapStack.top()[variableName];
if (it->constBegin() != statics.fakeValue.constBegin())
ret = *it;
return ret;
}
} while (vmi != m_valuemapStack.begin());
}
return m_valuemapStack.top()[variableName];
}
ProStringList QMakeEvaluator::values(const ProKey &variableName) const
{
for (int i = m_valuemapStack.size(); --i >= 0; ) {
ProValueMap::ConstIterator it = m_valuemapStack.at(i).constFind(variableName);
if (it != m_valuemapStack.at(i).constEnd()) {
ProValueMapStack::ConstIterator vmi = m_valuemapStack.constEnd();
do {
--vmi;
ProValueMap::ConstIterator it = (*vmi).constFind(variableName);
if (it != (*vmi).constEnd()) {
if (it->constBegin() == statics.fakeValue.constBegin())
break;
return *it;
}
}
} while (vmi != m_valuemapStack.constBegin());
return ProStringList();
}
......
......@@ -71,6 +71,8 @@ public:
virtual void doneWithEval(ProFile *parent) = 0;
};
typedef QStack<ProValueMap> ProValueMapStack;
class QMAKE_EXPORT QMakeEvaluator
{
public:
......@@ -265,7 +267,7 @@ public:
ProString m_dirSep;
ProFunctionDefs m_functionDefs;
ProStringList m_returnValue;
QStack<ProValueMap> m_valuemapStack; // VariableName must be us-ascii, the content however can be non-us-ascii.
ProValueMapStack m_valuemapStack; // VariableName must be us-ascii, the content however can be non-us-ascii.
QString m_tmp1, m_tmp2, m_tmp3, m_tmp[2]; // Temporaries for efficient toQString
mutable QString m_mtmp;
......
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