From 79a7572bf2aa42ca246cb7efd53e3dac2cd426bc Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Tue, 9 Feb 2010 14:09:24 +0100 Subject: QNAM HTTP: Reserve bytes for HTTP parsing Reviewed-by: Peter Hartmann --- src/network/access/qhttpnetworkreply.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index c56a3a3..6615410 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -423,6 +423,11 @@ int QHttpNetworkReplyPrivate::gunzipBodyPartially(QByteArray &compressed, QByteA qint64 QHttpNetworkReplyPrivate::readStatus(QAbstractSocket *socket) { + if (fragment.isEmpty()) { + // reserve bytes for the status line. This is better than always append() which reallocs the byte array + fragment.reserve(32); + } + qint64 bytes = 0; char c; qint64 haveRead = 0; @@ -502,6 +507,13 @@ bool QHttpNetworkReplyPrivate::parseStatus(const QByteArray &status) qint64 QHttpNetworkReplyPrivate::readHeader(QAbstractSocket *socket) { + if (fragment.isEmpty()) { + // according to http://dev.opera.com/articles/view/mama-http-headers/ the average size of the header + // block is 381 bytes. + // reserve bytes. This is better than always append() which reallocs the byte array. + fragment.reserve(512); + } + qint64 bytes = 0; char c = 0; bool allHeaders = false; -- cgit v0.12