qmake: use new QString::arg(QStringView) overload

Add ProString::toQStringView() to avoid creating QStrings just to pass
them to QString::arg() (single-arg; multiArg() does not, yet, accept
QStringViews).

I could have used the existing toQStringRef() function, but QStringRef
is a tad more complex to copy and quite a bit less future-proof.

Change-Id: I344c46f301768e844c487d36ce3e6cb276de8843
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
This commit is contained in:
Marc Mutz 2017-04-07 17:10:37 +02:00
parent cdbe9d1483
commit f5d8ad61a4
4 changed files with 26 additions and 25 deletions

View File

@ -139,6 +139,7 @@ public:
static uint hash(const QChar *p, int n); static uint hash(const QChar *p, int n);
ALWAYS_INLINE QStringRef toQStringRef() const { return QStringRef(&m_string, m_offset, m_length); } ALWAYS_INLINE QStringRef toQStringRef() const { return QStringRef(&m_string, m_offset, m_length); }
ALWAYS_INLINE QStringView toQStringView() const { return QStringView(m_string).mid(m_offset, m_length); }
ALWAYS_INLINE ProKey &toKey() { return *(ProKey *)this; } ALWAYS_INLINE ProKey &toKey() { return *(ProKey *)this; }
ALWAYS_INLINE const ProKey &toKey() const { return *(const ProKey *)this; } ALWAYS_INLINE const ProKey &toKey() const { return *(const ProKey *)this; }

View File

@ -592,7 +592,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
} }
} else { } else {
if (args.count() != 1) { if (args.count() != 1) {
evalError(fL1S("%1(var) requires one argument.").arg(func.toQString(m_tmp1))); evalError(fL1S("%1(var) requires one argument.").arg(func.toQStringView()));
} else { } else {
var = args[0]; var = args[0];
regexp = true; regexp = true;
@ -626,7 +626,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
} else { } else {
QString tmp = args.at(0).toQString(m_tmp1); QString tmp = args.at(0).toQString(m_tmp1);
for (int i = 1; i < args.count(); ++i) for (int i = 1; i < args.count(); ++i)
tmp = tmp.arg(args.at(i).toQString(m_tmp2)); tmp = tmp.arg(args.at(i).toQStringView());
ret << (tmp.isSharedWith(m_tmp1) ? args.at(0) : ProString(tmp).setSource(args.at(0))); ret << (tmp.isSharedWith(m_tmp1) ? args.at(0) : ProString(tmp).setSource(args.at(0)));
} }
break; break;
@ -659,7 +659,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
leftalign = true; leftalign = true;
} else { } else {
evalError(fL1S("format_number(): invalid format option %1.") evalError(fL1S("format_number(): invalid format option %1.")
.arg(opt.toQString(m_tmp3))); .arg(opt.toQStringView()));
goto formfail; goto formfail;
} }
} }
@ -672,7 +672,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
qlonglong num = args.at(0).toLongLong(&ok, ibase); qlonglong num = args.at(0).toLongLong(&ok, ibase);
if (!ok) { if (!ok) {
evalError(fL1S("format_number(): malformed number %2 for base %1.") evalError(fL1S("format_number(): malformed number %2 for base %1.")
.arg(ibase).arg(args.at(0).toQString(m_tmp3))); .arg(ibase).arg(args.at(0).toQStringView()));
break; break;
} }
QString outstr; QString outstr;
@ -714,7 +714,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
qlonglong num = arg.toLongLong(&ok); qlonglong num = arg.toLongLong(&ok);
if (!ok) { if (!ok) {
evalError(fL1S("num_add(): malformed number %1.") evalError(fL1S("num_add(): malformed number %1.")
.arg(arg.toQString(m_tmp3))); .arg(arg.toQStringView()));
goto nafail; goto nafail;
} }
sum += num; sum += num;
@ -801,7 +801,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
case E_FIRST: case E_FIRST:
case E_LAST: case E_LAST:
if (args.count() != 1) { if (args.count() != 1) {
evalError(fL1S("%1(var) requires one argument.").arg(func.toQString(m_tmp1))); evalError(fL1S("%1(var) requires one argument.").arg(func.toQStringView()));
} else { } else {
const ProStringList &var = values(map(args.at(0))); const ProStringList &var = values(map(args.at(0)));
if (!var.isEmpty()) { if (!var.isEmpty()) {
@ -815,7 +815,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
case E_TAKE_FIRST: case E_TAKE_FIRST:
case E_TAKE_LAST: case E_TAKE_LAST:
if (args.count() != 1) { if (args.count() != 1) {
evalError(fL1S("%1(var) requires one argument.").arg(func.toQString(m_tmp1))); evalError(fL1S("%1(var) requires one argument.").arg(func.toQStringView()));
} else { } else {
ProStringList &var = valuesRef(map(args.at(0))); ProStringList &var = valuesRef(map(args.at(0)));
if (!var.isEmpty()) { if (!var.isEmpty()) {
@ -1143,7 +1143,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
case E_RESOLVE_DEPENDS: case E_RESOLVE_DEPENDS:
if (args.count() < 1 || args.count() > 4) { if (args.count() < 1 || args.count() > 4) {
evalError(fL1S("%1(var, [prefix, [suffixes, [prio-suffix]]]) requires one to four arguments.") evalError(fL1S("%1(var, [prefix, [suffixes, [prio-suffix]]]) requires one to four arguments.")
.arg(func.toQString(m_tmp1))); .arg(func.toQStringView()));
} else { } else {
QHash<ProKey, QSet<ProKey> > dependencies; QHash<ProKey, QSet<ProKey> > dependencies;
ProValueMap dependees; ProValueMap dependees;
@ -1284,7 +1284,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
} }
break; break;
default: default:
evalError(fL1S("Function '%1' is not implemented.").arg(func.toQString(m_tmp1))); evalError(fL1S("Function '%1' is not implemented.").arg(func.toQStringView()));
break; break;
} }
@ -1314,7 +1314,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
return returnBool(findValues(var, &it)); return returnBool(findValues(var, &it));
} }
evalError(fL1S("defined(function, type): unexpected type [%1].") evalError(fL1S("defined(function, type): unexpected type [%1].")
.arg(args.at(1).toQString(m_tmp1))); .arg(args.at(1).toQStringView()));
return ReturnFalse; return ReturnFalse;
} }
return returnBool(m_functionDefs.replaceFunctions.contains(var) return returnBool(m_functionDefs.replaceFunctions.contains(var)
@ -1524,7 +1524,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
|| comp == QLatin1String("=") || comp == QLatin1String("==")) { || comp == QLatin1String("=") || comp == QLatin1String("==")) {
// fallthrough // fallthrough
} else { } else {
evalError(fL1S("Unexpected modifier to count(%2).").arg(comp.toQString(m_tmp1))); evalError(fL1S("Unexpected modifier to count(%2).").arg(comp.toQStringView()));
return ReturnFalse; return ReturnFalse;
} }
} }
@ -1534,7 +1534,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
case T_LESSTHAN: { case T_LESSTHAN: {
if (args.count() != 2) { if (args.count() != 2) {
evalError(fL1S("%1(variable, value) requires two arguments.") evalError(fL1S("%1(variable, value) requires two arguments.")
.arg(function.toQString(m_tmp1))); .arg(function.toQStringView()));
return ReturnFalse; return ReturnFalse;
} }
const ProString &rhs = args.at(1); const ProString &rhs = args.at(1);
@ -1556,16 +1556,16 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
case T_EQUALS: case T_EQUALS:
if (args.count() != 2) { if (args.count() != 2) {
evalError(fL1S("%1(variable, value) requires two arguments.") evalError(fL1S("%1(variable, value) requires two arguments.")
.arg(function.toQString(m_tmp1))); .arg(function.toQStringView()));
return ReturnFalse; return ReturnFalse;
} }
return returnBool(values(map(args.at(0))).join(statics.field_sep) return returnBool(values(map(args.at(0))).join(statics.field_sep)
== args.at(1).toQString(m_tmp1)); == args.at(1).toQStringView());
case T_VERSION_AT_LEAST: case T_VERSION_AT_LEAST:
case T_VERSION_AT_MOST: { case T_VERSION_AT_MOST: {
if (args.count() != 2) { if (args.count() != 2) {
evalError(fL1S("%1(variable, versionNumber) requires two arguments.") evalError(fL1S("%1(variable, versionNumber) requires two arguments.")
.arg(function.toQString(m_tmp1))); .arg(function.toQStringView()));
return ReturnFalse; return ReturnFalse;
} }
const QVersionNumber lvn = QVersionNumber::fromString(values(args.at(0).toKey()).join('.')); const QVersionNumber lvn = QVersionNumber::fromString(values(args.at(0).toKey()).join('.'));
@ -1577,7 +1577,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
case T_CLEAR: { case T_CLEAR: {
if (args.count() != 1) { if (args.count() != 1) {
evalError(fL1S("%1(variable) requires one argument.") evalError(fL1S("%1(variable) requires one argument.")
.arg(function.toQString(m_tmp1))); .arg(function.toQStringView()));
return ReturnFalse; return ReturnFalse;
} }
ProValueMap *hsh; ProValueMap *hsh;
@ -1594,7 +1594,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
case T_UNSET: { case T_UNSET: {
if (args.count() != 1) { if (args.count() != 1) {
evalError(fL1S("%1(variable) requires one argument.") evalError(fL1S("%1(variable) requires one argument.")
.arg(function.toQString(m_tmp1))); .arg(function.toQStringView()));
return ReturnFalse; return ReturnFalse;
} }
ProValueMap *hsh; ProValueMap *hsh;
@ -1701,7 +1701,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
case T_MESSAGE: { case T_MESSAGE: {
if (args.count() != 1) { if (args.count() != 1) {
evalError(fL1S("%1(message) requires one argument.") evalError(fL1S("%1(message) requires one argument.")
.arg(function.toQString(m_tmp1))); .arg(function.toQStringView()));
return ReturnFalse; return ReturnFalse;
} }
const QString &msg = m_option->expandEnvVars(args.at(0).toQString(m_tmp2)); const QString &msg = m_option->expandEnvVars(args.at(0).toQString(m_tmp2));
@ -1917,7 +1917,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
srcvar = dstvar; srcvar = dstvar;
ProValueMap::Iterator srcvarIt; ProValueMap::Iterator srcvarIt;
if (!findValues(srcvar, &srcvarIt)) { if (!findValues(srcvar, &srcvarIt)) {
evalError(fL1S("Variable %1 is not defined.").arg(srcvar.toQString(m_tmp1))); evalError(fL1S("Variable %1 is not defined.").arg(srcvar.toQStringView()));
return ReturnFalse; return ReturnFalse;
} }
// The caches for the host and target may differ (e.g., when we are manipulating // The caches for the host and target may differ (e.g., when we are manipulating
@ -2046,7 +2046,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
#endif #endif
return ReturnTrue; return ReturnTrue;
default: default:
evalError(fL1S("Function '%1' is not implemented.").arg(function.toQString(m_tmp1))); evalError(fL1S("Function '%1' is not implemented.").arg(function.toQStringView()));
return ReturnFalse; return ReturnFalse;
} }
} }

View File

@ -1582,7 +1582,7 @@ ProString QMakeEvaluator::propertyValue(const ProKey &name) const
return ProString(m_mkspecPaths.join(m_option->dirlist_sep)); return ProString(m_mkspecPaths.join(m_option->dirlist_sep));
ProString ret = m_option->propertyValue(name); ProString ret = m_option->propertyValue(name);
// if (ret.isNull()) // if (ret.isNull())
// evalError(fL1S("Querying unknown property %1").arg(name.toQString(m_mtmp))); // evalError(fL1S("Querying unknown property %1").arg(name.toQStringView()));
return ret; return ret;
} }
@ -1775,7 +1775,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditionalFunction(
} }
skipExpression(tokPtr); skipExpression(tokPtr);
evalError(fL1S("'%1' is not a recognized test function.").arg(func.toQString(m_tmp1))); evalError(fL1S("'%1' is not a recognized test function.").arg(func.toQStringView()));
return ReturnFalse; return ReturnFalse;
} }
@ -1801,7 +1801,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateExpandFunction(
} }
skipExpression(tokPtr); skipExpression(tokPtr);
evalError(fL1S("'%1' is not a recognized replace function.").arg(func.toQString(m_tmp1))); evalError(fL1S("'%1' is not a recognized replace function.").arg(func.toQStringView()));
return ReturnFalse; return ReturnFalse;
} }

View File

@ -91,7 +91,7 @@ bool QMakeProject::test(const ProKey &func, const QList<ProStringList> &args)
return boolRet(evaluateBoolFunction(*it, args, func)); return boolRet(evaluateBoolFunction(*it, args, func));
evalError(QStringLiteral("'%1' is not a recognized test function.") evalError(QStringLiteral("'%1' is not a recognized test function.")
.arg(func.toQString(m_tmp1))); .arg(func.toQStringView()));
return false; return false;
} }
@ -116,7 +116,7 @@ QStringList QMakeProject::expand(const ProKey &func, const QList<ProStringList>
} }
evalError(QStringLiteral("'%1' is not a recognized replace function.") evalError(QStringLiteral("'%1' is not a recognized replace function.")
.arg(func.toQString(m_tmp1))); .arg(func.toQStringView()));
return QStringList(); return QStringList();
} }