diff --git a/src/base/http/requestparser.cpp b/src/base/http/requestparser.cpp index fa5ded1c8..524c57772 100644 --- a/src/base/http/requestparser.cpp +++ b/src/base/http/requestparser.cpp @@ -253,7 +253,7 @@ bool RequestParser::parsePostMessage(const QByteArray &data) // split data by "dash-boundary" const QByteArray dashDelimiter = QByteArray("--") + delimiter + CRLF; - QList multipart = splitToViews(data, dashDelimiter, QString::SkipEmptyParts); + QVector multipart = splitToViews(data, dashDelimiter, QString::SkipEmptyParts); if (multipart.isEmpty()) { qWarning() << Q_FUNC_INFO << "multipart empty"; return false; @@ -275,7 +275,7 @@ bool RequestParser::parsePostMessage(const QByteArray &data) bool RequestParser::parseFormData(const QByteArray &data) { - const QList list = splitToViews(data, EOH, QString::KeepEmptyParts); + const QVector list = splitToViews(data, EOH, QString::KeepEmptyParts); if (list.size() != 2) { qWarning() << Q_FUNC_INFO << "multipart/form-data format error"; diff --git a/src/base/search/searchpluginmanager.cpp b/src/base/search/searchpluginmanager.cpp index d751cdf80..12d5280b4 100644 --- a/src/base/search/searchpluginmanager.cpp +++ b/src/base/search/searchpluginmanager.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include @@ -494,13 +493,13 @@ void SearchPluginManager::parseVersionInfo(const QByteArray &info) QHash updateInfo; int numCorrectData = 0; - const QList lines = Utils::ByteArray::splitToViews(info, "\n", QString::SkipEmptyParts); + const QVector lines = Utils::ByteArray::splitToViews(info, "\n", QString::SkipEmptyParts); for (QByteArray line : lines) { line = line.trimmed(); if (line.isEmpty()) continue; if (line.startsWith('#')) continue; - const QList list = Utils::ByteArray::splitToViews(line, ":", QString::SkipEmptyParts); + const QVector list = Utils::ByteArray::splitToViews(line, ":", QString::SkipEmptyParts); if (list.size() != 2) continue; const QString pluginName = list.first().trimmed(); diff --git a/src/base/utils/bytearray.cpp b/src/base/utils/bytearray.cpp index 9ef543e25..128aa93a3 100644 --- a/src/base/utils/bytearray.cpp +++ b/src/base/utils/bytearray.cpp @@ -28,15 +28,17 @@ #include "bytearray.h" -#include +#include -QList Utils::ByteArray::splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior) +QVector Utils::ByteArray::splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior) { if (sep.isEmpty()) return {in}; - QList ret; - + QVector ret; + ret.reserve((behavior == QString::KeepEmptyParts) + ? (1 + (in.size() / sep.size())) + : (1 + (in.size() / (sep.size() + 1)))); int head = 0; while (head < in.size()) { int end = in.indexOf(sep, head); diff --git a/src/base/utils/bytearray.h b/src/base/utils/bytearray.h index a9e6e89ea..f0d055ecf 100644 --- a/src/base/utils/bytearray.h +++ b/src/base/utils/bytearray.h @@ -28,15 +28,17 @@ #pragma once -#include #include +#include + +class QByteArray; namespace Utils { namespace ByteArray { - // Mimic QString::split(sep, behavior) - QList splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior = QString::KeepEmptyParts); + // Mimic QString::splitRef(sep, behavior) + QVector splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior = QString::KeepEmptyParts); // Mimic QByteArray::mid(pos, len) but instead of returning a full-copy, // we only return a partial view diff --git a/src/base/utils/foreignapps.cpp b/src/base/utils/foreignapps.cpp index 8047a827d..f32b55e45 100644 --- a/src/base/utils/foreignapps.cpp +++ b/src/base/utils/foreignapps.cpp @@ -43,6 +43,7 @@ #endif #include "base/logger.h" +#include "base/utils/bytearray.h" using namespace Utils::ForeignApps; @@ -61,7 +62,7 @@ namespace // Software 'Anaconda' installs its own python interpreter // and `python --version` returns a string like this: // "Python 3.4.3 :: Anaconda 2.3.0 (64-bit)" - const QList outputSplit = procOutput.split(' '); + const QVector outputSplit = Utils::ByteArray::splitToViews(procOutput, " ", QString::SkipEmptyParts); if (outputSplit.size() <= 1) return false; diff --git a/src/base/utils/password.cpp b/src/base/utils/password.cpp index ec9257ab5..e7bf0cbf6 100644 --- a/src/base/utils/password.cpp +++ b/src/base/utils/password.cpp @@ -33,7 +33,6 @@ #include #include -#include #include #include "bytearray.h" @@ -99,7 +98,7 @@ bool Utils::Password::PBKDF2::verify(const QByteArray &secret, const QString &pa bool Utils::Password::PBKDF2::verify(const QByteArray &secret, const QByteArray &password) { - const QList list = ByteArray::splitToViews(secret, ":", QString::SkipEmptyParts); + const QVector list = ByteArray::splitToViews(secret, ":", QString::SkipEmptyParts); if (list.size() != 2) return false;