summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2009-09-21 17:44:57 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2009-11-11 10:38:33 (GMT)
commitafffa7cd099379d78ada4c96c2284e87f77d7bb2 (patch)
treeaee4f1fb3bc40381614bc3a9673f1dd1d88c9ef8 /src
parent1502df3ddedc5a4365e12bce570d946744259785 (diff)
downloadQt-afffa7cd099379d78ada4c96c2284e87f77d7bb2.zip
Qt-afffa7cd099379d78ada4c96c2284e87f77d7bb2.tar.gz
Qt-afffa7cd099379d78ada4c96c2284e87f77d7bb2.tar.bz2
QNAM: Avoid using toLower for case insensitive comparision
Using qstricmp is faster on the desktop than the alloc of QByteArray::toLower and the QByteArray::operator==. QChar::toLower will now be called for the input key from within the loop. In the measurements done this is still a performance improvement over the allocation done by QByteArray::toLower. For more header values this might not be the case anymore. RESULT : tst_Loading::byteArrayTestLower(): 0.00076 msec per iteration (total: 25, iterations: 32768) RESULT : tst_Loading::byteArrayTestCompare(): 0.00028 msec per iteration (total: 37, iterations: 131072) Reviewed-By: Markus Goetz
Diffstat (limited to 'src')
-rw-r--r--src/network/access/qnetworkrequest.cpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index 86195c6..0e4326f 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -48,6 +48,8 @@
#include "QtCore/qlocale.h"
#include "QtCore/qdatetime.h"
+#include <ctype.h>
+
QT_BEGIN_NAMESPACE
/*!
@@ -606,26 +608,25 @@ static QNetworkRequest::KnownHeaders parseHeaderName(const QByteArray &headerNam
{
// headerName is not empty here
- QByteArray lower = headerName.toLower();
- switch (lower.at(0)) {
+ switch (tolower(headerName.at(0))) {
case 'c':
- if (lower == "content-type")
+ if (qstricmp(headerName.constData(), "content-type") == 0)
return QNetworkRequest::ContentTypeHeader;
- else if (lower == "content-length")
+ else if (qstricmp(headerName.constData(), "content-length") == 0)
return QNetworkRequest::ContentLengthHeader;
- else if (lower == "cookie")
+ else if (qstricmp(headerName.constData(), "cookie") == 0)
return QNetworkRequest::CookieHeader;
break;
case 'l':
- if (lower == "location")
+ if (qstricmp(headerName.constData(), "location") == 0)
return QNetworkRequest::LocationHeader;
- else if (lower == "last-modified")
+ else if (qstricmp(headerName.constData(), "last-modified") == 0)
return QNetworkRequest::LastModifiedHeader;
break;
case 's':
- if (lower == "set-cookie")
+ if (qstricmp(headerName.constData(), "set-cookie") == 0)
return QNetworkRequest::SetCookieHeader;
break;
}
@@ -697,11 +698,10 @@ static QVariant parseHeaderValue(QNetworkRequest::KnownHeaders header, const QBy
QNetworkHeadersPrivate::RawHeadersList::ConstIterator
QNetworkHeadersPrivate::findRawHeader(const QByteArray &key) const
{
- QByteArray lowerKey = key.toLower();
RawHeadersList::ConstIterator it = rawHeaders.constBegin();
RawHeadersList::ConstIterator end = rawHeaders.constEnd();
for ( ; it != end; ++it)
- if (it->first.toLower() == lowerKey)
+ if (qstricmp(it->first.constData(), key.constData()) == 0)
return it;
return end; // not found
@@ -775,10 +775,9 @@ void QNetworkHeadersPrivate::setCookedHeader(QNetworkRequest::KnownHeaders heade
void QNetworkHeadersPrivate::setRawHeaderInternal(const QByteArray &key, const QByteArray &value)
{
- QByteArray lowerKey = key.toLower();
RawHeadersList::Iterator it = rawHeaders.begin();
while (it != rawHeaders.end()) {
- if (it->first.toLower() == lowerKey)
+ if (qstricmp(it->first.constData(), key.constData()) == 0)
it = rawHeaders.erase(it);
else
++it;