mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-23 00:47:21 -06:00
Replace QString::split() by faster alternatives
This commit is contained in:
@@ -67,13 +67,15 @@ DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent)
|
||||
m_ui->textUrls->setWordWrapMode(QTextOption::NoWrap);
|
||||
|
||||
// Paste clipboard if there is an URL in it
|
||||
const QStringList clipboardList = qApp->clipboard()->text().split('\n');
|
||||
const QString clipboardText = qApp->clipboard()->text();
|
||||
const QVector<QStringRef> clipboardList = clipboardText.splitRef('\n');
|
||||
|
||||
QSet<QString> uniqueURLs;
|
||||
for (QString str : clipboardList) {
|
||||
str = str.trimmed();
|
||||
if (str.isEmpty()) continue;
|
||||
for (QStringRef strRef : clipboardList) {
|
||||
strRef = strRef.trimmed();
|
||||
if (strRef.isEmpty()) continue;
|
||||
|
||||
const QString str = strRef.toString();
|
||||
if (isDownloadable(str))
|
||||
uniqueURLs << str;
|
||||
}
|
||||
@@ -90,14 +92,15 @@ DownloadFromURLDialog::~DownloadFromURLDialog()
|
||||
|
||||
void DownloadFromURLDialog::downloadButtonClicked()
|
||||
{
|
||||
const QStringList urls = m_ui->textUrls->toPlainText().split('\n');
|
||||
const QString plainText = m_ui->textUrls->toPlainText();
|
||||
const QVector<QStringRef> urls = plainText.splitRef('\n');
|
||||
|
||||
QSet<QString> uniqueURLs;
|
||||
for (QString url : urls) {
|
||||
for (QStringRef url : urls) {
|
||||
url = url.trimmed();
|
||||
if (url.isEmpty()) continue;
|
||||
|
||||
uniqueURLs << url;
|
||||
uniqueURLs << url.toString();
|
||||
}
|
||||
|
||||
if (uniqueURLs.isEmpty()) {
|
||||
|
||||
@@ -1354,21 +1354,22 @@ void MainWindow::on_actionOpen_triggered()
|
||||
QFileDialog::getOpenFileNames(this, tr("Open Torrent Files"), pref->getMainLastDir(),
|
||||
tr("Torrent Files") + " (*" + C_TORRENT_FILE_EXTENSION + ')');
|
||||
|
||||
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
|
||||
if (!pathsList.isEmpty()) {
|
||||
for (const QString &file : pathsList) {
|
||||
qDebug("Dropped file %s on download list", qUtf8Printable(file));
|
||||
if (useTorrentAdditionDialog)
|
||||
AddNewTorrentDialog::show(file, this);
|
||||
else
|
||||
BitTorrent::Session::instance()->addTorrent(file);
|
||||
}
|
||||
if (pathsList.isEmpty())
|
||||
return;
|
||||
|
||||
// Save last dir to remember it
|
||||
QStringList topDir = Utils::Fs::toUniformPath(pathsList.at(0)).split('/');
|
||||
topDir.removeLast();
|
||||
pref->setMainLastDir(Utils::Fs::toUniformPath(topDir.join('/')));
|
||||
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
|
||||
|
||||
for (const QString &file : pathsList) {
|
||||
if (useTorrentAdditionDialog)
|
||||
AddNewTorrentDialog::show(file, this);
|
||||
else
|
||||
BitTorrent::Session::instance()->addTorrent(file);
|
||||
}
|
||||
|
||||
// Save last dir to remember it
|
||||
QString topDir = Utils::Fs::toUniformPath(pathsList.at(0));
|
||||
topDir = topDir.left(topDir.lastIndexOf('/'));
|
||||
pref->setMainLastDir(topDir);
|
||||
}
|
||||
|
||||
void MainWindow::activate()
|
||||
|
||||
@@ -139,10 +139,10 @@ bool ProgramUpdater::isVersionMoreRecent(const QString &remoteVersion) const
|
||||
{
|
||||
const QRegularExpressionMatch regVerMatch = QRegularExpression("([0-9.]+)").match(QBT_VERSION);
|
||||
if (regVerMatch.hasMatch()) {
|
||||
QString localVersion = regVerMatch.captured(1);
|
||||
qDebug() << Q_FUNC_INFO << "local version:" << localVersion << "/" << QBT_VERSION;
|
||||
QStringList remoteParts = remoteVersion.split('.');
|
||||
QStringList localParts = localVersion.split('.');
|
||||
const QString localVersion = regVerMatch.captured(1);
|
||||
const QVector<QStringRef> remoteParts = remoteVersion.splitRef('.');
|
||||
const QVector<QStringRef> localParts = localVersion.splitRef('.');
|
||||
|
||||
for (int i = 0; i < qMin(remoteParts.size(), localParts.size()); ++i) {
|
||||
if (remoteParts[i].toInt() > localParts[i].toInt())
|
||||
return true;
|
||||
|
||||
@@ -56,11 +56,13 @@ TrackersAdditionDialog::~TrackersAdditionDialog()
|
||||
|
||||
QStringList TrackersAdditionDialog::newTrackers() const
|
||||
{
|
||||
const QString plainText = m_ui->textEditTrackersList->toPlainText();
|
||||
|
||||
QStringList cleanTrackers;
|
||||
for (QString url : asConst(m_ui->textEditTrackersList->toPlainText().split('\n'))) {
|
||||
for (QStringRef url : asConst(plainText.splitRef('\n'))) {
|
||||
url = url.trimmed();
|
||||
if (!url.isEmpty())
|
||||
cleanTrackers << url;
|
||||
cleanTrackers << url.toString();
|
||||
}
|
||||
return cleanTrackers;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ void PluginSelectDialog::dropEvent(QDropEvent *event)
|
||||
}
|
||||
}
|
||||
else {
|
||||
files = event->mimeData()->text().split(QLatin1String("\n"));
|
||||
files = event->mimeData()->text().split('\n');
|
||||
}
|
||||
|
||||
if (files.isEmpty()) return;
|
||||
|
||||
@@ -469,14 +469,18 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info)
|
||||
// Iterate over files
|
||||
for (int i = 0; i < filesCount; ++i) {
|
||||
currentParent = m_rootItem;
|
||||
QString path = Utils::Fs::toUniformPath(info.filePath(i));
|
||||
const QString path = Utils::Fs::toUniformPath(info.filePath(i));
|
||||
|
||||
// Iterate of parts of the path to create necessary folders
|
||||
QStringList pathFolders = path.split('/', QString::SkipEmptyParts);
|
||||
QVector<QStringRef> pathFolders = path.splitRef('/', QString::SkipEmptyParts);
|
||||
pathFolders.removeLast();
|
||||
for (const QString &pathPart : asConst(pathFolders)) {
|
||||
if (pathPart == ".unwanted")
|
||||
|
||||
for (const QStringRef &pathPartRef : asConst(pathFolders)) {
|
||||
if (pathPartRef == QLatin1String(".unwanted"))
|
||||
continue;
|
||||
TorrentContentModelFolder* newParent = currentParent->childFolderWithName(pathPart);
|
||||
|
||||
const QString pathPart = pathPartRef.toString();
|
||||
TorrentContentModelFolder *newParent = currentParent->childFolderWithName(pathPart);
|
||||
if (!newParent) {
|
||||
newParent = new TorrentContentModelFolder(pathPart, currentParent);
|
||||
currentParent->appendChild(newParent);
|
||||
|
||||
Reference in New Issue
Block a user