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:
Chocobo1 2025-03-15 14:58:59 +08:00 committed by GitHub
parent d174bc75e4
commit 5a4b3b25d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 113 additions and 63 deletions

View file

@ -465,13 +465,13 @@ QBtCommandLineParameters parseCommandLine(const QStringList &args)
return result;
}
QString wrapText(const QString &text, int initialIndentation = USAGE_TEXT_COLUMN, int wrapAtColumn = WRAP_AT_COLUMN)
QString wrapText(const QString &text, const int initialIndentation = USAGE_TEXT_COLUMN, const int wrapAtColumn = WRAP_AT_COLUMN)
{
QStringList words = text.split(u' ');
const QStringList words = text.split(u' ');
QStringList lines = {words.first()};
int currentLineMaxLength = wrapAtColumn - initialIndentation;
for (const QString &word : asConst(words.mid(1)))
for (const QString &word : asConst(words.sliced(1)))
{
if (lines.last().length() + word.length() + 1 < currentLineMaxLength)
{