mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 21:28:07 -06:00
Use slice method where applicable
These code segments already have its boundary checked and can thus be faster. PR #22411.
This commit is contained in:
@@ -122,7 +122,7 @@ namespace
|
||||
fsPathEdit->setCurrentIndex(existingIndex);
|
||||
}
|
||||
|
||||
void updatePathHistory(const QString &settingsKey, const Path &path, const int maxLength)
|
||||
void updatePathHistory(const QString &settingsKey, const Path &path, const qsizetype maxLength)
|
||||
{
|
||||
// Add last used save path to the front of history
|
||||
|
||||
@@ -134,7 +134,10 @@ namespace
|
||||
else
|
||||
pathList.prepend(path.toString());
|
||||
|
||||
settings()->storeValue(settingsKey, QStringList(pathList.mid(0, maxLength)));
|
||||
if (pathList.size() > maxLength)
|
||||
pathList.resize(maxLength);
|
||||
|
||||
settings()->storeValue(settingsKey, pathList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,8 +378,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::TorrentDescriptor &to
|
||||
connect(Preferences::instance(), &Preferences::changed, []
|
||||
{
|
||||
const int length = Preferences::instance()->addNewTorrentDialogSavePathHistoryLength();
|
||||
settings()->storeValue(KEY_SAVEPATHHISTORY
|
||||
, QStringList(settings()->loadValue<QStringList>(KEY_SAVEPATHHISTORY).mid(0, length)));
|
||||
settings()->storeValue(KEY_SAVEPATHHISTORY, settings()->loadValue<QStringList>(KEY_SAVEPATHHISTORY).mid(0, length));
|
||||
});
|
||||
|
||||
setCurrentContext(std::make_shared<Context>(Context {torrentDescr, inParams}));
|
||||
|
||||
@@ -234,14 +234,14 @@ void FileSystemPathEdit::setFileNameFilter(const QString &val)
|
||||
const int closeBracePos = val.indexOf(u')', (openBracePos + 1));
|
||||
if ((openBracePos > 0) && (closeBracePos > 0) && (closeBracePos > openBracePos + 2))
|
||||
{
|
||||
QString filterString = val.mid(openBracePos + 1, closeBracePos - openBracePos - 1);
|
||||
const QString filterString = val.sliced((openBracePos + 1), (closeBracePos - openBracePos - 1));
|
||||
if (filterString == u"*")
|
||||
{ // no filters
|
||||
d->m_editor->setFilenameFilters({});
|
||||
}
|
||||
else
|
||||
{
|
||||
QStringList filters = filterString.split(u' ', Qt::SkipEmptyParts);
|
||||
const QStringList filters = filterString.split(u' ', Qt::SkipEmptyParts);
|
||||
d->m_editor->setFilenameFilters(filters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1859,10 +1859,10 @@ void OptionsDialog::setLocale(const QString &localeStr)
|
||||
if (index < 0)
|
||||
{
|
||||
//Attempt to find a language match without a country
|
||||
int pos = name.indexOf(u'_');
|
||||
const int pos = name.indexOf(u'_');
|
||||
if (pos > -1)
|
||||
{
|
||||
QString lang = name.left(pos);
|
||||
const QString lang = name.first(pos);
|
||||
index = m_ui->comboLanguage->findData(lang, Qt::UserRole);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,13 @@ namespace
|
||||
|
||||
QString relativePath = match.captured(6);
|
||||
if (relativePath.startsWith(u'/'))
|
||||
relativePath = relativePath.mid(1);
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
||||
relativePath.slice(1);
|
||||
#else
|
||||
relativePath.remove(0, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
const QString absoluteUrl = !host.isEmpty()
|
||||
? QString(defaultScheme + u':' + host) : (normalizedBaseUrl + relativePath);
|
||||
|
||||
@@ -46,7 +46,7 @@ void SearchSortModel::setNameFilter(const QString &searchTerm)
|
||||
{
|
||||
m_searchTerm = searchTerm;
|
||||
if ((searchTerm.length() > 2) && searchTerm.startsWith(u'"') && searchTerm.endsWith(u'"'))
|
||||
m_searchTermWords = QStringList(m_searchTerm.mid(1, m_searchTerm.length() - 2));
|
||||
m_searchTermWords = QStringList(m_searchTerm.sliced(1, (m_searchTerm.length() - 2)));
|
||||
else
|
||||
m_searchTermWords = searchTerm.split(u' ', Qt::SkipEmptyParts);
|
||||
}
|
||||
|
||||
@@ -675,7 +675,7 @@ void SearchWidget::loadHistory()
|
||||
}
|
||||
|
||||
if (history.size() > m_historyLength)
|
||||
history = history.mid(history.size() - m_historyLength);
|
||||
history.remove(0, (history.size() - m_historyLength));
|
||||
|
||||
m_searchPatternCompleterModel->setStringList(history);
|
||||
});
|
||||
|
||||
@@ -174,9 +174,9 @@ namespace
|
||||
{
|
||||
QString shortName(const QString &fullName)
|
||||
{
|
||||
int pos = fullName.lastIndexOf(u'/');
|
||||
const int pos = fullName.lastIndexOf(u'/');
|
||||
if (pos >= 0)
|
||||
return fullName.mid(pos + 1);
|
||||
return fullName.sliced(pos + 1);
|
||||
return fullName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -555,7 +555,7 @@ void TrackersFilterWidget::handleFavicoDownloadFinished(const Net::DownloadResul
|
||||
{
|
||||
if (result.url.endsWith(u".ico", Qt::CaseInsensitive))
|
||||
{
|
||||
const QString faviconURL = result.url.left(result.url.size() - 4) + u".png";
|
||||
const QString faviconURL = QStringView(result.url).chopped(4) + u".png";
|
||||
for (const auto &trackerHost : trackerHosts)
|
||||
{
|
||||
if (m_trackers.contains(trackerHost))
|
||||
|
||||
Reference in New Issue
Block a user