Commit 97af2386 authored by Friedemann Kleint's avatar Friedemann Kleint

Preferably use QStringRef::toInt().

Avoid allocations for converting to int.

Change-Id: Id8c79334f4809ec075ffe7e6b7635be4873eafd8
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 30b1e70c
......@@ -52,10 +52,10 @@ ComponentVersion::ComponentVersion(const QString &versionString)
if (dotIdx == -1)
return;
bool ok = false;
int maybeMajor = versionString.left(dotIdx).toInt(&ok);
int maybeMajor = versionString.leftRef(dotIdx).toInt(&ok);
if (!ok)
return;
int maybeMinor = versionString.mid(dotIdx + 1).toInt(&ok);
int maybeMinor = versionString.midRef(dotIdx + 1).toInt(&ok);
if (!ok)
return;
_major = maybeMajor;
......
......@@ -108,8 +108,8 @@ void TypeDescriptionReader::readDocument(UiProgram *ast)
const QString versionString = _source.mid(import->versionToken.offset, import->versionToken.length);
const int dotIdx = versionString.indexOf(QLatin1Char('.'));
if (dotIdx != -1) {
version = ComponentVersion(versionString.left(dotIdx).toInt(),
versionString.mid(dotIdx + 1).toInt());
version = ComponentVersion(versionString.leftRef(dotIdx).toInt(),
versionString.midRef(dotIdx + 1).toInt());
}
if (version.majorVersion() != 1) {
addError(import->versionToken, tr("Major version different from 1 not supported."));
......
......@@ -79,7 +79,7 @@ QColor QmlJS::toQColor(const QString &qmlColorString)
QColor color;
if (qmlColorString.size() == 9 && qmlColorString.at(0) == QLatin1Char('#')) {
bool ok;
const int alpha = qmlColorString.mid(1, 2).toInt(&ok, 16);
const int alpha = qmlColorString.midRef(1, 2).toInt(&ok, 16);
if (ok) {
QString name(qmlColorString.at(0));
name.append(qmlColorString.right(6));
......
......@@ -347,7 +347,7 @@ void AndroidConfig::updateNdkInformation() const
QDirIterator it(path.appendPath(QLatin1String("platforms")).toString(), QStringList() << QLatin1String("android-*"), QDir::Dirs);
while (it.hasNext()) {
const QString &fileName = it.next();
m_availableNdkPlatforms.push_back(fileName.mid(fileName.lastIndexOf(QLatin1Char('-')) + 1).toInt());
m_availableNdkPlatforms.push_back(fileName.midRef(fileName.lastIndexOf(QLatin1Char('-')) + 1).toInt());
}
Utils::sort(m_availableNdkPlatforms, std::greater<int>());
......@@ -907,7 +907,7 @@ QString AndroidConfig::getAvdName(const QString &serialnumber)
if (index == -1)
return QString();
bool ok;
int port = serialnumber.mid(index + 1).toInt(&ok);
int port = serialnumber.midRef(index + 1).toInt(&ok);
if (!ok)
return QString();
......
......@@ -318,7 +318,7 @@ QList<int> AndroidToolChainFactory::versionNumberFromString(const QString &versi
index = end;
bool ok;
int v = version.mid(start, index - start).toInt(&ok);
int v = version.midRef(start, index - start).toInt(&ok);
if (!ok) // unparseable, return what we have
return result;
......
......@@ -48,7 +48,7 @@ static QString decode(const QString& original)
while ((pos = regex.indexIn(original, pos)) != -1) {
const QString value = regex.cap(1);
if (value.startsWith(QLatin1Char('x')))
result.replace(regex.cap(0), QChar(value.mid(1).toInt(0, 16)));
result.replace(regex.cap(0), QChar(value.midRef(1).toInt(0, 16)));
else
result.replace(regex.cap(0), QChar(value.toInt(0, 10)));
pos += regex.matchedLength();
......
......@@ -809,7 +809,7 @@ void BookmarkManager::addBookmark(const QString &s)
if (index3 != -1 || index2 != -1 || index1 != -1) {
const QString &filePath = s.mid(index1+1, index2-index1-1);
const QString &note = s.mid(index3 + 1);
const int lineNumber = s.mid(index2 + 1, index3 - index2 - 1).toInt();
const int lineNumber = s.midRef(index2 + 1, index3 - index2 - 1).toInt();
if (!filePath.isEmpty() && !findBookmark(filePath, lineNumber)) {
Bookmark *b = new Bookmark(lineNumber, this);
b->updateFileName(filePath);
......
......@@ -1134,7 +1134,7 @@ void ClearCasePlugin::diffActivity()
// pre-first version. only for the first occurrence
if (filever[file].first.isEmpty()) {
int verpos = shortver.lastIndexOf(QRegExp(QLatin1String("[^0-9]"))) + 1;
int vernum = shortver.mid(verpos).toInt();
int vernum = shortver.midRef(verpos).toInt();
if (vernum)
--vernum;
shortver.replace(verpos, shortver.length() - verpos, QString::number(vernum));
......
......@@ -231,8 +231,8 @@ QString previousRevision(const QString &rev)
const int dotPos = rev.lastIndexOf(QLatin1Char('.'));
if (dotPos == -1)
return rev;
const int minor = rev.mid(dotPos + 1).toInt();
return rev.left(dotPos + 1) + QString::number(minor - 1);
const int minor = rev.midRef(dotPos + 1).toInt();
return rev.leftRef(dotPos + 1) + QString::number(minor - 1);
}
// Is "[1.2...].1"?
......
......@@ -898,7 +898,7 @@ void DebuggerToolTipHolder::positionShow(const TextEditorWidget *editorWidget)
static QDate dateFromString(const QString &date)
{
return date.size() == 8 ?
QDate(date.left(4).toInt(), date.mid(4, 2).toInt(), date.mid(6, 2).toInt()) :
QDate(date.leftRef(4).toInt(), date.midRef(4, 2).toInt(), date.midRef(6, 2).toInt()) :
QDate();
}
......
......@@ -349,7 +349,7 @@ ContextData getLocationContext(TextDocument *document, int lineNumber)
if (!fileName.isEmpty()) {
// Possibly one of the "27 [1] foo = x" lines
int pos = line.indexOf(QLatin1Char('['));
int ln = line.left(pos - 1).toInt();
int ln = line.leftRef(pos - 1).toInt();
if (ln > 0) {
data.type = LocationByFile;
data.fileName = fileName;
......
......@@ -5465,7 +5465,7 @@ bool FakeVimHandler::Private::handleExSubstituteCommand(const ExCommand &cmd)
QString line = cmd.args;
const int countIndex = line.lastIndexOf(QRegExp(_("\\d+$")));
if (countIndex != -1) {
count = line.mid(countIndex).toInt();
count = line.midRef(countIndex).toInt();
line = line.mid(0, countIndex).trimmed();
}
......
......@@ -109,7 +109,7 @@ void GerritPushDialog::initRemoteBranches()
continue;
const QString ref = entries.at(0).mid(remotesPrefix.size());
int refBranchIndex = ref.indexOf(QLatin1Char('/'));
int timeT = entries.at(1).left(entries.at(1).indexOf(QLatin1Char(' '))).toInt();
int timeT = entries.at(1).leftRef(entries.at(1).indexOf(QLatin1Char(' '))).toInt();
BranchDate bd(ref.mid(refBranchIndex + 1), QDateTime::fromTime_t(timeT).date());
m_remoteBranches.insertMulti(ref.left(refBranchIndex), bd);
}
......
......@@ -243,7 +243,7 @@ static inline QString nextStash(const QString &stash)
if (closingBracePos == -1)
return QString();
bool ok;
const int n = stash.mid(openingBracePos + 1, closingBracePos - openingBracePos - 1).toInt(&ok);
const int n = stash.midRef(openingBracePos + 1, closingBracePos - openingBracePos - 1).toInt(&ok);
if (!ok)
return QString();
QString rc = stash.left(openingBracePos + 1);
......
......@@ -445,7 +445,7 @@ Abi::Abi(const QString &abiString) :
return;
bool ok = false;
int bitCount = bits.left(bits.count() - 3).toInt(&ok);
int bitCount = bits.leftRef(bits.count() - 3).toInt(&ok);
if (!ok)
return;
if (bitCount != 8 && bitCount != 16 && bitCount != 32 && bitCount != 64)
......@@ -830,7 +830,7 @@ QList<Abi> Abi::abisOfBinary(const Utils::FileName &path)
const QString fileName = QString::fromLocal8Bit(data.mid(0, 16));
quint64 fileNameOffset = 0;
if (fileName.startsWith(QLatin1String("#1/")))
fileNameOffset = fileName.mid(3).toInt();
fileNameOffset = fileName.midRef(3).toInt();
const QString fileLength = QString::fromLatin1(data.mid(48, 10));
int toSkip = 60 + fileNameOffset;
......
......@@ -375,9 +375,9 @@ AbstractMsvcToolChain::WarningFlagAdder::WarningFlagAdder(const QString &flag,
}
bool ok = false;
if (m_doesEnable)
m_warningCode = flag.mid(2).toInt(&ok);
m_warningCode = flag.midRef(2).toInt(&ok);
else
m_warningCode = flag.mid(3).toInt(&ok);
m_warningCode = flag.midRef(3).toInt(&ok);
if (!ok)
m_triggered = true;
}
......
......@@ -210,7 +210,7 @@ static QList<DeviceProcessItem> getLocalProcessesUsingPs()
if (cmdSep > 0) {
const int argsSep = cmdSep != -1 ? line.indexOf(blank, cmdSep + 1) : -1;
DeviceProcessItem procData;
procData.pid = line.left(pidSep).toInt();
procData.pid = line.leftRef(pidSep).toInt();
procData.cmdLine = line.mid(cmdSep + 1);
if (argsSep == -1)
procData.exe = line.mid(cmdSep + 1);
......
......@@ -47,7 +47,7 @@ static QPair<Utils::FileName, int> parseFileName(const QString &input)
int pos = fileName.lastIndexOf(QLatin1Char('('));
if (pos >= 0) {
bool ok = false;
int n = fileName.mid(pos + 1, fileName.count() - pos - 2).toInt(&ok);
int n = fileName.midRef(pos + 1, fileName.count() - pos - 2).toInt(&ok);
if (ok) {
fileName = fileName.left(pos);
linenumber = n;
......
......@@ -642,7 +642,7 @@ QList<ToolChain *> MsvcToolChainFactory::autoDetect(const QList<ToolChain *> &al
QString path = QDir::fromNativeSeparators(vsRegistry.value(vsName).toString());
if (path.endsWith(QLatin1Char('/')))
path.chop(1);
const int version = vsName.left(dotPos).toInt();
const int version = vsName.leftRef(dotPos).toInt();
const QString vcvarsAllbat = path + QLatin1String("/vcvarsall.bat");
if (QFileInfo(vcvarsAllbat).isFile()) {
QList<MsvcToolChain::Platform> platforms; // prioritized list
......
......@@ -2005,7 +2005,7 @@ UserFileVersion11Upgrader::~UserFileVersion11Upgrader()
static inline int targetId(const QString &targetKey)
{
return targetKey.mid(targetKey.lastIndexOf(QLatin1Char('.')) + 1).toInt();
return targetKey.midRef(targetKey.lastIndexOf(QLatin1Char('.')) + 1).toInt();
}
QVariantMap UserFileVersion11Upgrader::upgrade(const QVariantMap &map)
......
......@@ -393,7 +393,7 @@ QList<ToolChain *> WinCEToolChainFactory::autoDetect(const QList<ToolChain *> &a
continue;
const QString path = QDir::fromNativeSeparators(vsRegistry.value(vsName).toString());
const int version = vsName.left(dotPos).toInt();
const int version = vsName.leftRef(dotPos).toInt();
// Check existence of various install scripts
const QString vcvars32bat = path + QLatin1String("bin/vcvars32.bat");
......
......@@ -79,7 +79,7 @@ static void splitIdInBaseNameAndNumber(const QString &id, QString *baseId, int *
int counter = 0;
while (counter < id.count()) {
bool canConvertToInteger = false;
int newNumber = id.right(counter +1).toInt(&canConvertToInteger);
int newNumber = id.rightRef(counter +1).toInt(&canConvertToInteger);
if (canConvertToInteger)
*number = newNumber;
else
......
......@@ -208,7 +208,7 @@ static bool restoreQtVersions()
if (!key.startsWith(keyPrefix))
continue;
bool ok;
int count = key.mid(keyPrefix.count()).toInt(&ok);
int count = key.midRef(keyPrefix.count()).toInt(&ok);
if (!ok || count < 0)
continue;
......@@ -282,7 +282,7 @@ void QtVersionManager::updateFromInstaller(bool emitSignal)
if (!key.startsWith(keyPrefix))
continue;
bool ok;
int count = key.mid(keyPrefix.count()).toInt(&ok);
int count = key.midRef(keyPrefix.count()).toInt(&ok);
if (!ok || count < 0)
continue;
......
......@@ -87,7 +87,7 @@ private:
continue;
}
bool ok;
const int pid = elements.first().mid(6).toInt(&ok);
const int pid = elements.first().midRef(6).toInt(&ok);
if (!ok) {
qDebug("%s: Expected number in %s. Line was '%s'.", Q_FUNC_INFO,
qPrintable(elements.first()), qPrintable(visualizeNull(line)));
......
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