Replace QString::split() by faster alternatives

This commit is contained in:
Chocobo1
2019-08-06 23:07:57 +08:00
parent 1eeac90a29
commit b5b678c58f
12 changed files with 73 additions and 53 deletions

View File

@@ -32,9 +32,9 @@
#include <QProcess>
#include <QTimer>
#include "../global.h"
#include "../utils/foreignapps.h"
#include "../utils/fs.h"
#include "base/global.h"
#include "base/utils/foreignapps.h"
#include "base/utils/fs.h"
#include "searchpluginmanager.h"
namespace
@@ -161,24 +161,29 @@ void SearchHandler::processFailed()
// file url | file name | file size | nb seeds | nb leechers | Search engine url
bool SearchHandler::parseSearchResult(const QString &line, SearchResult &searchResult)
{
const QStringList parts = line.split('|');
const QVector<QStringRef> parts = line.splitRef('|');
const int nbFields = parts.size();
if (nbFields < (NB_PLUGIN_COLUMNS - 1)) return false; // -1 because desc_link is optional
searchResult = SearchResult();
searchResult.fileUrl = parts.at(PL_DL_LINK).trimmed(); // download URL
searchResult.fileName = parts.at(PL_NAME).trimmed(); // Name
searchResult.fileUrl = parts.at(PL_DL_LINK).trimmed().toString(); // download URL
searchResult.fileName = parts.at(PL_NAME).trimmed().toString(); // Name
searchResult.fileSize = parts.at(PL_SIZE).trimmed().toLongLong(); // Size
bool ok = false;
searchResult.nbSeeders = parts.at(PL_SEEDS).trimmed().toLongLong(&ok); // Seeders
if (!ok || (searchResult.nbSeeders < 0))
searchResult.nbSeeders = -1;
searchResult.nbLeechers = parts.at(PL_LEECHS).trimmed().toLongLong(&ok); // Leechers
if (!ok || (searchResult.nbLeechers < 0))
searchResult.nbLeechers = -1;
searchResult.siteUrl = parts.at(PL_ENGINE_URL).trimmed(); // Search site URL
searchResult.siteUrl = parts.at(PL_ENGINE_URL).trimmed().toString(); // Search site URL
if (nbFields == NB_PLUGIN_COLUMNS)
searchResult.descrLink = parts.at(PL_DESC_LINK).trimmed(); // Description Link
searchResult.descrLink = parts.at(PL_DESC_LINK).trimmed().toString(); // Description Link
return true;
}

View File

@@ -376,8 +376,10 @@ void SearchPluginManager::pluginDownloadFinished(const Net::DownloadResult &resu
Utils::Fs::forceRemove(filePath);
}
else {
QString pluginName = result.url.split('/').last();
const QString url = result.url;
QString pluginName = url.mid(url.lastIndexOf('/') + 1);
pluginName.replace(".py", "", Qt::CaseInsensitive);
if (pluginInfo(pluginName))
emit pluginUpdateFailed(pluginName, tr("Failed to download the plugin file. %1").arg(result.errorString));
else
@@ -462,7 +464,7 @@ void SearchPluginManager::update()
plugin->fullName = engineElem.elementsByTagName("name").at(0).toElement().text();
plugin->url = engineElem.elementsByTagName("url").at(0).toElement().text();
const auto categories = engineElem.elementsByTagName("categories").at(0).toElement().text().split(' ');
const QStringList categories = engineElem.elementsByTagName("categories").at(0).toElement().text().split(' ');
for (QString cat : categories) {
cat = cat.trimmed();
if (!cat.isEmpty())