From 65768082fe559d3746e8058da8e30c9599b109d6 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 3 Apr 2025 14:52:28 -0700 Subject: [PATCH] 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 Change-Id: I7908b9cf75742db07145fffd9499ce3b79492fdb Reviewed-by: David Faure (cherry picked from commit 7ed94ef2b510a51d81dbe8aa4700dc8a283b21aa) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qurl.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 65ef0cbdb2b..7f95a570bd7 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -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