diff --git a/src/network/access/qhttpheaders.cpp b/src/network/access/qhttpheaders.cpp index b4477ffb717..3e2f0e718b8 100644 --- a/src/network/access/qhttpheaders.cpp +++ b/src/network/access/qhttpheaders.cpp @@ -1063,6 +1063,18 @@ qsizetype QHttpHeaders::size() const noexcept return d->headers.size(); } +/*! + Attempts to allocate memory for at least \a size header entries. + + If you know in advance how how many header entries there will + be, you may call this function to prevent reallocations + and memory fragmentation. +*/ +void QHttpHeaders::reserve(qsizetype size) +{ + d->headers.reserve(size); +} + /*! Compares this instance with \a other and returns \c true if they are considered equal in accordance with the provided \a options. diff --git a/src/network/access/qhttpheaders.h b/src/network/access/qhttpheaders.h index 695094f473c..d59a8ae3bd3 100644 --- a/src/network/access/qhttpheaders.h +++ b/src/network/access/qhttpheaders.h @@ -247,6 +247,7 @@ public: Q_NETWORK_EXPORT QByteArray combinedValue(WellKnownHeader name) const; Q_NETWORK_EXPORT qsizetype size() const noexcept; + Q_NETWORK_EXPORT void reserve(qsizetype size); bool isEmpty() const noexcept { return size() == 0; } Q_NETWORK_EXPORT bool equals(const QHttpHeaders &other,