qmljs: improve code a bit

Change-Id: Iea7bdb5c1a0340b60a3e9efd1e9369403af4fabd
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Tim Jenssen
2020-11-12 17:44:10 +01:00
parent 32e455c12e
commit 01d509a100

View File

@@ -298,13 +298,13 @@ ImportMatchStrength ImportKey::matchImport(const ImportKey &o, const ViewerConte
if (dirToFile) if (dirToFile)
--lenPath1; --lenPath1;
int iSelector = 0; int iSelector = 0;
int nSelectors = vContext.selectors.size(); const int nSelectors = vContext.selectors.size();
while (iPath1 < lenPath1) { while (iPath1 < lenPath1) {
if (lenPath2 - iPath2 > lenPath1 - iPath1) if (lenPath2 - iPath2 > lenPath1 - iPath1)
return ImportMatchStrength(); return ImportMatchStrength();
QString p1 = splitPath.at(iPath1); const QString p1 = splitPath.at(iPath1);
if (iPath2 < lenPath2) { if (iPath2 < lenPath2) {
QString p2 = splitPath.at(iPath2); const QString p2 = splitPath.at(iPath2);
if (p1 == p2) { if (p1 == p2) {
++iPath1; ++iPath1;
++iPath2; ++iPath2;
@@ -312,7 +312,7 @@ ImportMatchStrength ImportKey::matchImport(const ImportKey &o, const ViewerConte
} }
} }
if (!p1.startsWith(QLatin1Char('+'))) if (!p1.startsWith(QLatin1Char('+')))
return QList<int>(); return ImportMatchStrength();
const QStringView selectorAtt(p1.constData() + 1, p1.size() - 1); const QStringView selectorAtt(p1.constData() + 1, p1.size() - 1);
while (iSelector < nSelectors) { while (iSelector < nSelectors) {
if (selectorAtt == vContext.selectors.at(iSelector)) if (selectorAtt == vContext.selectors.at(iSelector))
@@ -320,16 +320,16 @@ ImportMatchStrength ImportKey::matchImport(const ImportKey &o, const ViewerConte
++iSelector; ++iSelector;
} }
if (iSelector == nSelectors) if (iSelector == nSelectors)
return QList<int>(); return ImportMatchStrength();
res << (nSelectors - iSelector); res << (nSelectors - iSelector);
++iSelector; ++iSelector;
++iPath1; ++iPath1;
} }
if (iPath2 != lenPath2) if (iPath2 != lenPath2)
return QList<int>(); return ImportMatchStrength();
if (res.isEmpty()) if (res.isEmpty())
res << 0; res << 0;
return ImportMatchStrength(res); return ImportMatchStrength(res);
} }
int ImportKey::compare(const ImportKey &other) const int ImportKey::compare(const ImportKey &other) const