Commit 840e7871 authored by Friedemann Kleint's avatar Friedemann Kleint

Use QString::splitRef() instead of QString::split()

Avoid string allocation where it seems feasible.

Change-Id: I61b23d4ef8a459f5aa77727a75f4e1d2b140da3b
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 90fb7c79
......@@ -411,7 +411,7 @@ void CMakeTool::fetchVersionFromVersionOutput() const
return;
QRegularExpression versionLine("^cmake version ((\\d+).(\\d+).(\\d+).*)$");
for (const QString &line : response.stdOut().split('\n')) {
for (const QStringRef &line : response.stdOut().splitRef(QLatin1Char('\n'))) {
QRegularExpressionMatch match = versionLine.match(line);
if (!match.hasMatch())
continue;
......
......@@ -703,14 +703,14 @@ QString DocumentManager::getSaveFileName(const QString &title, const QString &pa
const int index = regExp.lastIndexIn(*selectedFilter);
if (index != -1) {
bool suffixOk = false;
const QStringList &suffixes = regExp.cap(1).remove(QLatin1Char('*')).split(QLatin1Char(' '));
foreach (const QString &suffix, suffixes)
const QVector<QStringRef> suffixes = regExp.cap(1).remove(QLatin1Char('*')).splitRef(QLatin1Char(' '));
foreach (const QStringRef &suffix, suffixes)
if (fileName.endsWith(suffix)) {
suffixOk = true;
break;
}
if (!suffixOk && !suffixes.isEmpty())
fileName.append(suffixes.at(0));
fileName.append(suffixes.at(0).toString());
}
}
if (QFile::exists(fileName)) {
......
......@@ -228,8 +228,8 @@ bool BreakpointParameters::isCppBreakpoint() const
if (qmlExtensionString.isEmpty())
qmlExtensionString = ".qml;.js";
auto qmlFileExtensions = qmlExtensionString.split(";", QString::SkipEmptyParts);
foreach (QString extension, qmlFileExtensions) {
auto qmlFileExtensions = qmlExtensionString.splitRef(QLatin1Char(';'), QString::SkipEmptyParts);
foreach (QStringRef extension, qmlFileExtensions) {
if (fileName.endsWith(extension, Qt::CaseInsensitive))
return false;
}
......
......@@ -2071,7 +2071,7 @@ void CdbEngine::ensureUsing32BitStackInWow64(const DebuggerResponse &response, c
{
// Parsing the header of the stack output to check which bitness
// the cdb is currently using.
foreach (const QString &line, response.data.data().split('\n')) {
foreach (const QStringRef &line, response.data.data().splitRef(QLatin1Char('\n'))) {
if (!line.startsWith("Child"))
continue;
if (line.startsWith("ChildEBP")) {
......@@ -2909,7 +2909,8 @@ void CdbEngine::setupScripting(const DebuggerResponse &response)
return;
}
const QString &verOutput = data.data();
const QStringList pythonVersion = verOutput.split(' ').first().split('.');
const QVector<QStringRef> pythonVersion =
verOutput.split(QLatin1Char(' ')).constFirst().splitRef(QLatin1Char('.'));
bool ok = false;
if (pythonVersion.size() == 3) {
......
......@@ -822,9 +822,9 @@ QString DebuggerCommand::argsToString() const
DebuggerEncoding::DebuggerEncoding(const QString &data)
{
const QStringList l = data.split(':');
const QVector<QStringRef> l = data.splitRef(QLatin1Char(':'));
const QString &t = l.at(0);
const QStringRef &t = l.at(0);
if (t == "latin1") {
type = HexEncodedLatin1;
size = 1;
......
......@@ -3515,14 +3515,14 @@ void GdbEngine::handleRegisterListing(const DebuggerResponse &response)
m_registers.clear();
QStringList lines = response.consoleStreamOutput.split('\n');
for (int i = 1; i < lines.size(); ++i) {
QStringList parts = QString(lines.at(i)).split(' ', QString::SkipEmptyParts);
const QVector<QStringRef> parts = QString(lines.at(i)).splitRef(' ', QString::SkipEmptyParts);
if (parts.size() < 7)
continue;
int gdbRegisterNumber = parts.at(1).toInt();
Register reg;
reg.name = parts.at(0);
reg.name = parts.at(0).toString();
reg.size = parts.at(4).toInt();
reg.reportedType = parts.at(5);
reg.reportedType = parts.at(5).toString();
m_registers[gdbRegisterNumber] = reg;
}
}
......@@ -3895,7 +3895,7 @@ static SourcePathMap mergeStartParametersSourcePathMap(const DebuggerRunParamete
void GdbEngine::startGdb(const QStringList &args)
{
const QString tests = QString::fromLocal8Bit(qgetenv("QTC_DEBUGGER_TESTS"));
foreach (const QString &test, tests.split(','))
foreach (const QStringRef &test, tests.splitRef(QLatin1Char(',')))
m_testCases.insert(test.toInt());
foreach (int test, m_testCases)
showMessage("ENABLING TEST CASE: " + QString::number(test));
......
......@@ -2531,7 +2531,7 @@ void WatchHandler::addDumpers(const GdbMi &dumpers)
DisplayFormats formats;
formats.append(RawFormat);
QString reportedFormats = dumper["formats"].data();
foreach (const QString &format, reportedFormats.split(',')) {
foreach (const QStringRef &format, reportedFormats.splitRef(',')) {
if (int f = format.toInt())
formats.append(DisplayFormat(f));
}
......
......@@ -352,7 +352,7 @@ Abi::Abi(const QString &abiString) :
m_architecture(UnknownArchitecture), m_os(UnknownOS),
m_osFlavor(UnknownFlavor), m_binaryFormat(UnknownFormat), m_wordWidth(0)
{
QStringList abiParts = abiString.split(QLatin1Char('-'));
const QVector<QStringRef> abiParts = abiString.splitRef(QLatin1Char('-'));
if (abiParts.count() >= 1) {
if (abiParts.at(0) == QLatin1String("unknown"))
m_architecture = UnknownArchitecture;
......@@ -453,12 +453,14 @@ Abi::Abi(const QString &abiString) :
}
if (abiParts.count() >= 5) {
const QString &bits = abiParts.at(4);
const QStringRef &bits = abiParts.at(4);
if (!bits.endsWith(QLatin1String("bit")))
return;
bool ok = false;
int bitCount = bits.leftRef(bits.count() - 3).toInt(&ok);
const QStringRef number =
bits.string()->midRef(bits.position(), bits.count() - 3);
const int bitCount = number.toInt(&ok);
if (!ok)
return;
if (bitCount != 8 && bitCount != 16 && bitCount != 32 && bitCount != 64)
......@@ -473,7 +475,7 @@ Abi Abi::abiFromTargetTriplet(const QString &triple)
if (machine.isEmpty())
return Abi();
QStringList parts = machine.split(QRegExp(QLatin1String("[ /-]")));
const QVector<QStringRef> parts = machine.splitRef(QRegExp(QLatin1String("[ /-]")));
Abi::Architecture arch = Abi::UnknownArchitecture;
Abi::OS os = Abi::UnknownOS;
......@@ -482,7 +484,7 @@ Abi Abi::abiFromTargetTriplet(const QString &triple)
unsigned char width = 0;
int unknownCount = 0;
foreach (const QString &p, parts) {
for (const QStringRef &p : parts) {
if (p == QLatin1String("unknown") || p == QLatin1String("pc") || p == QLatin1String("none")
|| p == QLatin1String("gnu") || p == QLatin1String("uclibc")
|| p == QLatin1String("86_64") || p == QLatin1String("redhat")
......
......@@ -415,8 +415,8 @@ void Highlighter::changeContext(const QString &contextName,
const bool assignCurrent)
{
if (contextName.startsWith(kPop)) {
QStringList list = contextName.split(kHash, QString::SkipEmptyParts);
for (int i = 0; i < list.size(); ++i) {
const int count = contextName.splitRef(kHash, QString::SkipEmptyParts).size();
for (int i = 0; i < count; ++i) {
if (m_contexts.isEmpty()) {
throw HighlighterException(
QCoreApplication::translate("GenericHighlighter", "Reached empty context."));
......
......@@ -61,7 +61,7 @@ void LineNumberFilter::prepareSearch(const QString &entry)
QList<LocatorFilterEntry> LineNumberFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &, const QString &entry)
{
QList<LocatorFilterEntry> value;
QStringList lineAndColumn = entry.split(QLatin1Char(':'));
const QVector<QStringRef> lineAndColumn = entry.splitRef(QLatin1Char(':'));
int sectionCount = lineAndColumn.size();
int line = 0;
int column = 0;
......
......@@ -327,7 +327,7 @@ void Parser::Private::parseHeader(QIODevice *device)
} else if (line.startsWith("summary: ")) {
QString values = getValue(line, 9);
uint i = 0;
foreach (const QString &value, values.split(QLatin1Char(' '), QString::SkipEmptyParts))
foreach (const QStringRef &value, values.splitRef(QLatin1Char(' '), QString::SkipEmptyParts))
data->setTotalCost(i++, value.toULongLong());
} else if (!line.trimmed().isEmpty()) {
// handle line and exit parseHeader
......
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