summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-03-11 10:28:06 +0100
committerMarc Mutz <[email protected]>2025-03-11 18:45:40 +0100
commit8761fa5b8bec2f9b80550523e824f4e3141aca49 (patch)
treef80dc815a2999d474348e62cfa2c0301ecf56598
parent53bfe72967270bc7c448bd892f4a406a389b779b (diff)
QHttpHeaders: de-pessimize Private::replaceOrAppend()
All callers of replaceOrAppend() (present and future) pass an rvalue `value`, so take advantage of C++17 guaranteed copy elision, take `value` by value and move it into place. Even for implicitly-shared classes, a move (pointer swap) is cheaper than a copy (atomic ref-count upping/downing; ca. 100x slower than a normal int). Amends d8f6425fef1050525480afec662a417a7645c22e. Pick-to: 6.9 6.8 Change-Id: Ia52a2ec2c079f515f92b0890e42669d4ba435c20 Reviewed-by: Juha Vuolle <[email protected]>
-rw-r--r--src/network/access/qhttpheaders.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/network/access/qhttpheaders.cpp b/src/network/access/qhttpheaders.cpp
index bc702e1a82f..ec109df5c3a 100644
--- a/src/network/access/qhttpheaders.cpp
+++ b/src/network/access/qhttpheaders.cpp
@@ -791,7 +791,7 @@ public:
// we can define common methods which 'detach()' the private itself.
using Self = QExplicitlySharedDataPointer<QHttpHeadersPrivate>;
static void removeAll(Self &d, const HeaderName &name);
- static void replaceOrAppend(Self &d, const HeaderName &name, const QByteArray &value);
+ static void replaceOrAppend(Self &d, const HeaderName &name, QByteArray value);
void combinedValue(const HeaderName &name, QByteArray &result) const;
void values(const HeaderName &name, QList<QByteArray> &result) const;
@@ -855,20 +855,20 @@ QByteArrayView QHttpHeadersPrivate::value(const HeaderName &name, QByteArrayView
return defaultValue;
}
-void QHttpHeadersPrivate::replaceOrAppend(Self &d, const HeaderName &name, const QByteArray &value)
+void QHttpHeadersPrivate::replaceOrAppend(Self &d, const HeaderName &name, QByteArray value)
{
d.detach();
auto it = std::find_if(d->headers.begin(), d->headers.end(), headerNameMatches(name));
if (it != d->headers.end()) {
// Found something to replace => replace, and then rearrange any remaining
// matches to the end and erase them
- it->value = value;
+ it->value = std::move(value);
d->headers.erase(
std::remove_if(it + 1, d->headers.end(), headerNameMatches(name)),
d->headers.end());
} else {
// Found nothing to replace => append
- d->headers.append(Header{name, value});
+ d->headers.append(Header{name, std::move(value)});
}
}