QUrl::adjusted: remove unnecessary temporary variable

We don't need to QUrlPrivate::appendPath() to a temporary variable under
QUrl::FullyEncoded mode and then setPath(). We can simply ask
appendPath() to write to the destination variable once and for all, so
long as we take care to ask it to use the encoding form that setPath()
uses (QUrl::PrettyDecoded, which is 0x0). That avoids the side trip
through FullyEncoded mode.

Pick-to: 6.8 6.9
Change-Id: I7908b9cf75742db07145fffd9499ce3b79492fdb
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Thiago Macieira 2025-04-03 14:52:28 -07:00
parent f3da9d3c85
commit 7ed94ef2b5

View File

@ -2895,11 +2895,10 @@ QUrl QUrl::adjusted(QUrl::FormattingOptions options) const
that.setFragment(QString());
if (options & RemovePath) {
that.setPath(QString());
} else if (options & (StripTrailingSlash | RemoveFilename | NormalizePathSegments)) {
} else if (auto pathOpts = options & (StripTrailingSlash | RemoveFilename | NormalizePathSegments)) {
that.detach();
QString path;
d->appendPath(path, options | FullyEncoded, QUrlPrivate::Path);
that.d->setPath(path, 0, path.size());
that.d->path.resize(0);
d->appendPath(that.d->path, pathOpts, QUrlPrivate::Path);
}
if (that.d->isLocalFile() && that.d->path.startsWith(u'/')) {
// ensure absolute file URLs have an empty authority to comply with the