add some future safety

detaching an empty vector does not necessarily do anything.
on the downsite, as the sentinel value is not empty any more, we need to
explicitly clear it out when we meet it.

Change-Id: I0f15aa3d421706a5423bf37f3173a807d0d49c53
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
This commit is contained in:
Oswald Buddenhagen
2012-07-03 12:18:47 +02:00
parent abb210e719
commit 087021a23c

View File

@@ -419,7 +419,7 @@ void ProFileEvaluator::Private::initStatics()
statics.reg_variableName.setPattern(QLatin1String("\\$\\(.*\\)"));
statics.reg_variableName.setMinimal(true);
statics.fakeValue.detach(); // It has to have a unique begin() value
statics.fakeValue = ProStringList(ProString("_FAKE_")); // It has to have a unique begin() value
static const struct {
const char * const name;
@@ -3119,12 +3119,16 @@ QHash<ProString, ProStringList> *ProFileEvaluator::Private::findValues(
ProStringList &ProFileEvaluator::Private::valuesRef(const ProString &variableName)
{
QHash<ProString, ProStringList>::Iterator it = m_valuemapStack.top().find(variableName);
if (it != m_valuemapStack.top().end())
if (it != m_valuemapStack.top().end()) {
if (it->constBegin() == statics.fakeValue.constBegin())
it->clear();
return *it;
}
for (int i = m_valuemapStack.size() - 1; --i >= 0; ) {
QHash<ProString, ProStringList>::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;
}