avoid exponential resource consumption

the cumulative mode tries hard to never lose already assigned variable
values. the naive implementation turned assignments into additions,
which made the trivial construct "FOO = $$FOO" double the size of the
array each time it would be executed.
so instead let the assignments be assignments, and then re-add the
values that would be dropped.

Reviewed-by: dt
Task-number: QTCREATORBUG-1595
This commit is contained in:
Oswald Buddenhagen
2010-06-24 11:03:52 +02:00
parent 0fd0e6a9d0
commit 74fd5a560f

View File

@@ -1211,9 +1211,22 @@ void ProFileEvaluator::Private::visitProVariable(ProVariable *var)
m_valuemapStack.top()[varName] = varVal; m_valuemapStack.top()[varName] = varVal;
m_filevaluemap[currentProFile()][varName] = varVal; m_filevaluemap[currentProFile()][varName] = varVal;
} }
} else { } else if (!varVal.isEmpty()) {
// We are greedy for values. // We are greedy for values. But avoid exponential growth.
valuesRef(varName) += varVal; QStringList &v = valuesRef(varName);
if (v.isEmpty()) {
v = varVal;
} else {
QStringList old = v;
v = varVal;
QSet<QString> has = v.toSet();
v.reserve(v.size() + old.size());
foreach (const QString &s, old)
if (!has.contains(s))
v << s;
}
// These values will not be used for further processing inside
// the evaluator. Duplicate elimination happens later.
m_filevaluemap[currentProFile()][varName] += varVal; m_filevaluemap[currentProFile()][varName] += varVal;
} }
break; break;
@@ -3346,7 +3359,7 @@ ProFileEvaluator::TemplateType ProFileEvaluator::templateType()
{ {
QStringList templ = values(statics.strTEMPLATE); QStringList templ = values(statics.strTEMPLATE);
if (templ.count() >= 1) { if (templ.count() >= 1) {
const QString &t = templ.last(); const QString &t = templ.at(0);
if (!t.compare(QLatin1String("app"), Qt::CaseInsensitive)) if (!t.compare(QLatin1String("app"), Qt::CaseInsensitive))
return TT_Application; return TT_Application;
if (!t.compare(QLatin1String("lib"), Qt::CaseInsensitive)) if (!t.compare(QLatin1String("lib"), Qt::CaseInsensitive))