Commit 2cc17a61 authored by Daniel Teske's avatar Daniel Teske

QmakeGlobals::expandEnvVars: Make sane

Use indexOf() to match individual characters, which is a lot faster than
QRegExp. As a side effect, don't try to expand what we just inserted.

Change-Id: I964fbd92055f2f2649e7d8ed5739cf1fc7cae927
Reviewed-by: default avatarOswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent a5828911
......@@ -70,27 +70,8 @@ QT_BEGIN_NAMESPACE
#define fL1S(s) QString::fromLatin1(s)
namespace { // MSVC doesn't seem to know the semantics of "static" ...
static struct {
QRegExp reg_variableName;
} statics;
}
static void initStatics()
{
if (!statics.reg_variableName.isEmpty())
return;
statics.reg_variableName.setPattern(QLatin1String("\\$\\(.*\\)"));
statics.reg_variableName.setMinimal(true);
}
QMakeGlobals::QMakeGlobals()
{
initStatics();
do_cache = true;
#ifdef PROEVALUATOR_DEBUG
......@@ -288,11 +269,24 @@ QStringList QMakeGlobals::getPathListEnv(const QString &var) const
QString QMakeGlobals::expandEnvVars(const QString &str) const
{
QString string = str;
int rep;
QRegExp reg_variableName = statics.reg_variableName; // Copy for thread safety
while ((rep = reg_variableName.indexIn(string)) != -1)
string.replace(rep, reg_variableName.matchedLength(),
getEnv(string.mid(rep + 2, reg_variableName.matchedLength() - 3)));
int startIndex = 0;
forever {
startIndex = string.indexOf(QLatin1Char('$'), startIndex);
if (startIndex < 0)
break;
if (string.length() < startIndex + 3)
break;
if (string.at(startIndex + 1) != QLatin1Char('(')) {
startIndex++;
continue;
}
int endIndex = string.indexOf(QLatin1Char(')'), startIndex + 2);
if (endIndex < 0)
break;
QString value = getEnv(string.mid(startIndex + 2, endIndex - startIndex - 2));
string.replace(startIndex, endIndex - startIndex + 1, value);
startIndex += value.length();
}
return string;
}
......
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