Skip to content

Commit

Permalink
QHttpHeaders: Self-Encapsulate Field d->headers
Browse files Browse the repository at this point in the history
Use QHttpHeaders::reserve() and QHttpHeaders::isEmpty() instead of
going directly to d->headers. Will help in enabling a nullptr d.

Pick-to: 6.7
Change-Id: Id530f8922b17058ec47530523ed43e08927c3ce3
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
  • Loading branch information
marcmutz committed Jan 26, 2024
1 parent 119a6b5 commit f5056a0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/network/access/qhttpheaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ QHttpHeaders::QHttpHeaders() : d(new QHttpHeadersPrivate)
QHttpHeaders QHttpHeaders::fromListOfPairs(const QList<std::pair<QByteArray, QByteArray>> &headers)
{
QHttpHeaders h;
h.d->headers.reserve(headers.size());
h.reserve(headers.size());
for (const auto &header : headers)
h.append(header.first, header.second);
return h;
Expand All @@ -500,7 +500,7 @@ QHttpHeaders QHttpHeaders::fromListOfPairs(const QList<std::pair<QByteArray, QBy
QHttpHeaders QHttpHeaders::fromMultiMap(const QMultiMap<QByteArray, QByteArray> &headers)
{
QHttpHeaders h;
h.d->headers.reserve(headers.size());
h.reserve(headers.size());
for (const auto &[name,value] : headers.asKeyValueRange())
h.append(name, value);
return h;
Expand All @@ -515,7 +515,7 @@ QHttpHeaders QHttpHeaders::fromMultiMap(const QMultiMap<QByteArray, QByteArray>
QHttpHeaders QHttpHeaders::fromMultiHash(const QMultiHash<QByteArray, QByteArray> &headers)
{
QHttpHeaders h;
h.d->headers.reserve(headers.size());
h.reserve(headers.size());
for (const auto &[name,value] : headers.asKeyValueRange())
h.append(name, value);
return h;
Expand Down Expand Up @@ -1097,7 +1097,7 @@ QMultiHash<QByteArray, QByteArray> QHttpHeaders::toMultiHash() const
*/
void QHttpHeaders::clear()
{
if (d->headers.isEmpty())
if (isEmpty())
return;
d.detach();
d->headers.clear();
Expand Down

0 comments on commit f5056a0

Please sign in to comment.