qmake: make yet more use of ProString::toQStringRef()
in most cases, the main advantage is not using toQString(m_tmp), which reduces the possibility of raw data leaks. in cases where we used toQString() without temporary, this is a slight optimization. Change-Id: Ib343acffd383aa2c4fefab75fb52762fb534dfc6 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
parent
d293f071f5
commit
eb0ba90b0a
@ -74,6 +74,11 @@ ProString::ProString(const QString &str) :
|
||||
{
|
||||
}
|
||||
|
||||
ProString::ProString(const QStringRef &str) :
|
||||
m_string(*str.string()), m_offset(str.position()), m_length(str.size()), m_file(0), m_hash(0x80000000)
|
||||
{
|
||||
}
|
||||
|
||||
ProString::ProString(const char *str, DoPreHashing) :
|
||||
m_string(QString::fromLatin1(str)), m_offset(0), m_length(qstrlen(str)), m_file(0)
|
||||
{
|
||||
@ -336,7 +341,7 @@ ProString ProString::trimmed() const
|
||||
|
||||
QTextStream &operator<<(QTextStream &t, const ProString &str)
|
||||
{
|
||||
t << str.toQString(); // XXX optimize ... somehow
|
||||
t << str.toQStringRef();
|
||||
return t;
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,7 @@ public:
|
||||
ProString();
|
||||
ProString(const ProString &other);
|
||||
PROITEM_EXPLICIT ProString(const QString &str);
|
||||
PROITEM_EXPLICIT ProString(const QStringRef &str);
|
||||
PROITEM_EXPLICIT ProString(const char *str);
|
||||
ProString(const QString &str, int offset, int length);
|
||||
void setValue(const QString &str);
|
||||
@ -94,6 +95,7 @@ public:
|
||||
|
||||
bool operator==(const ProString &other) const { return toQStringRef() == other.toQStringRef(); }
|
||||
bool operator==(const QString &other) const { return toQStringRef() == other; }
|
||||
bool operator==(const QStringRef &other) const { return toQStringRef() == other; }
|
||||
bool operator==(QLatin1String other) const { return toQStringRef() == other; }
|
||||
bool operator==(const char *other) const { return toQStringRef() == QLatin1String(other); }
|
||||
bool operator!=(const ProString &other) const { return !(*this == other); }
|
||||
@ -203,9 +205,9 @@ Q_DECLARE_TYPEINFO(ProKey, Q_MOVABLE_TYPE);
|
||||
uint qHash(const ProString &str);
|
||||
QString operator+(const ProString &one, const ProString &two);
|
||||
inline QString operator+(const ProString &one, const QString &two)
|
||||
{ return one + ProString(two); }
|
||||
{ return one.toQStringRef() + two; }
|
||||
inline QString operator+(const QString &one, const ProString &two)
|
||||
{ return ProString(one) + two; }
|
||||
{ return one + two.toQStringRef(); }
|
||||
|
||||
inline QString operator+(const ProString &one, const char *two)
|
||||
{ QString ret = one.toQStringRef() + QLatin1String(two); ret.detach(); return ret; }
|
||||
|
@ -731,9 +731,9 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
|
||||
const QString &sep = (args.count() == 2) ? args.at(1).toQString(m_tmp1) : statics.field_sep;
|
||||
const auto vars = values(map(args.at(0)));
|
||||
for (const ProString &var : vars) {
|
||||
const auto splits = var.toQString(m_tmp2).split(sep);
|
||||
for (const QString &splt : splits)
|
||||
ret << (splt.isSharedWith(m_tmp2) ? var : ProString(splt).setSource(var));
|
||||
const auto splits = var.toQStringRef().split(sep);
|
||||
for (const auto &splt : splits)
|
||||
ret << ProString(splt).setSource(var);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1431,7 +1431,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
|
||||
}
|
||||
if (args.count() == 1)
|
||||
return returnBool(isActiveConfig(args.at(0).toQStringRef()));
|
||||
const QStringList &mutuals = args.at(1).toQString(m_tmp2).split(QLatin1Char('|'));
|
||||
const auto &mutuals = args.at(1).toQStringRef().split(QLatin1Char('|'));
|
||||
const ProStringList &configs = values(statics.strCONFIG);
|
||||
|
||||
for (int i = configs.size() - 1; i >= 0; i--) {
|
||||
@ -1465,7 +1465,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
|
||||
t ^= 1;
|
||||
}
|
||||
} else {
|
||||
const QStringList &mutuals = args.at(2).toQString(m_tmp3).split(QLatin1Char('|'));
|
||||
const auto &mutuals = args.at(2).toQStringRef().split(QLatin1Char('|'));
|
||||
for (int i = l.size() - 1; i >= 0; i--) {
|
||||
const ProString val = l[i];
|
||||
for (int mut = 0; mut < mutuals.count(); mut++) {
|
||||
@ -1536,7 +1536,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
|
||||
return ReturnFalse;
|
||||
}
|
||||
return returnBool(values(map(args.at(0))).join(statics.field_sep)
|
||||
== args.at(1).toQString(m_tmp1));
|
||||
== args.at(1).toQStringRef());
|
||||
case T_CLEAR: {
|
||||
if (args.count() != 1) {
|
||||
evalError(fL1S("%1(variable) requires one argument.")
|
||||
|
@ -775,7 +775,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProLoop(
|
||||
}
|
||||
infinite = true;
|
||||
} else {
|
||||
const QString &itl = it_list.toQString(m_tmp1);
|
||||
const QStringRef &itl = it_list.toQStringRef();
|
||||
int dotdot = itl.indexOf(statics.strDotDot);
|
||||
if (dotdot != -1) {
|
||||
bool ok;
|
||||
@ -872,13 +872,13 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProVariable(
|
||||
ProStringList varVal;
|
||||
if (expandVariableReferences(tokPtr, sizeHint, &varVal, true) == ReturnError)
|
||||
return ReturnError;
|
||||
const QString &val = varVal.at(0).toQString(m_tmp1);
|
||||
const QStringRef &val = varVal.at(0).toQStringRef();
|
||||
if (val.length() < 4 || val.at(0) != QLatin1Char('s')) {
|
||||
evalError(fL1S("The ~= operator can handle only the s/// function."));
|
||||
return ReturnTrue;
|
||||
}
|
||||
QChar sep = val.at(1);
|
||||
QStringList func = val.split(sep);
|
||||
auto func = val.split(sep);
|
||||
if (func.count() < 3 || func.count() > 4) {
|
||||
evalError(fL1S("The s/// function expects 3 or 4 arguments."));
|
||||
return ReturnTrue;
|
||||
@ -890,8 +890,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProVariable(
|
||||
case_sense = func[3].indexOf(QLatin1Char('i')) == -1;
|
||||
quote = func[3].indexOf(QLatin1Char('q')) != -1;
|
||||
}
|
||||
QString pattern = func[1];
|
||||
QString replace = func[2];
|
||||
QString pattern = func[1].toString();
|
||||
QString replace = func[2].toString();
|
||||
if (quote)
|
||||
pattern = QRegExp::escape(pattern);
|
||||
|
||||
|
@ -43,7 +43,7 @@
|
||||
r == ReturnNext ? "next" : \
|
||||
r == ReturnReturn ? "return" : \
|
||||
"<invalid>")
|
||||
# define dbgKey(s) qPrintable(s.toString().toQString())
|
||||
# define dbgKey(s) s.toString().toQStringRef().toLocal8Bit().constData()
|
||||
# define dbgStr(s) qPrintable(formatValue(s, true))
|
||||
# define dbgStrList(s) qPrintable(formatValueList(s))
|
||||
# define dbgSepStrList(s) qPrintable(formatValueList(s, true))
|
||||
|
Loading…
x
Reference in New Issue
Block a user