From dab3e21b2241ed8e06efbb30fdc32ad3a5ebef51 Mon Sep 17 00:00:00 2001
From: Holger Hans Peter Freyther <zecke@selfish.org>
Date: Tue, 22 Sep 2009 12:35:29 +0200
Subject: [PATCH 3/4] network: Remove some more occurences of toLower on the hot path

toLower will force a memory allocation, and memory allocations
are certainly adding a delay. Use qstricmp were this is easily
possible. This change makes headerValues et all drop out of
the profile.
---
 src/network/access/qhttpnetworkheader.cpp        |    6 ++----
 src/network/access/qhttpnetworkreply.cpp         |    6 +++---
 src/network/access/qnetworkaccesshttpbackend.cpp |    2 +-
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/network/access/qhttpnetworkheader.cpp b/src/network/access/qhttpnetworkheader.cpp
index 68ed3e5..e9866ca 100644
--- a/src/network/access/qhttpnetworkheader.cpp
+++ b/src/network/access/qhttpnetworkheader.cpp
@@ -92,11 +92,10 @@ QByteArray QHttpNetworkHeaderPrivate::headerField(const QByteArray &name, const
 QList<QByteArray> QHttpNetworkHeaderPrivate::headerFieldValues(const QByteArray &name) const
 {
     QList<QByteArray> result;
-    QByteArray lowerName = name.toLower();
     QList<QPair<QByteArray, QByteArray> >::ConstIterator it = fields.constBegin(),
                                                         end = fields.constEnd();
     for ( ; it != end; ++it)
-        if (lowerName == it->first.toLower())
+        if (qstricmp(name.constData(), it->first) == 0)
             result += it->second;
 
     return result;
@@ -104,10 +103,9 @@ QList<QByteArray> QHttpNetworkHeaderPrivate::headerFieldValues(const QByteArray
 
 void QHttpNetworkHeaderPrivate::setHeaderField(const QByteArray &name, const QByteArray &data)
 {
-    QByteArray lowerName = name.toLower();
     QList<QPair<QByteArray, QByteArray> >::Iterator it = fields.begin();
     while (it != fields.end()) {
-        if (lowerName == it->first.toLower())
+        if (qstricmp(name.constData(), it->first) == 0)
             it = fields.erase(it);
         else
             ++it;
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index c953ebf..c178490 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -238,7 +238,7 @@ qint64 QHttpNetworkReplyPrivate::bytesAvailable() const
 bool QHttpNetworkReplyPrivate::isGzipped()
 {
     QByteArray encoding = headerField("content-encoding");
-    return encoding.toLower() == "gzip";
+    return qstricmp(encoding.constData(), "gzip") == 0;
 }
 
 void QHttpNetworkReplyPrivate::removeAutoDecompressHeader()
@@ -246,11 +246,10 @@ void QHttpNetworkReplyPrivate::removeAutoDecompressHeader()
     // The header "Content-Encoding  = gzip" is retained.
     // Content-Length is removed since the actual one send by the server is for compressed data
     QByteArray name("content-length");
-    QByteArray lowerName = name.toLower();
     QList<QPair<QByteArray, QByteArray> >::Iterator it = fields.begin(),
                                                    end = fields.end();
     while (it != end) {
-        if (name == it->first.toLower()) {
+        if (qstricmp(name.constData(), it->first.constData()) == 0) {
             fields.erase(it);
             break;
         }
@@ -268,6 +267,7 @@ bool QHttpNetworkReplyPrivate::findChallenge(bool forProxy, QByteArray &challeng
     QList<QByteArray> challenges = headerFieldValues(header);
     for (int i = 0; i<challenges.size(); i++) {
         QByteArray line = challenges.at(i);
+        // todo use qstrincmp
         if (!line.toLower().startsWith("negotiate"))
             challenge = line;
     }
diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp
index c068f55..831bf5d 100644
--- a/src/network/access/qnetworkaccesshttpbackend.cpp
+++ b/src/network/access/qnetworkaccesshttpbackend.cpp
@@ -732,7 +732,7 @@ void QNetworkAccessHttpBackend::replyHeaderChanged()
     for (; it != end; ++it) {
         QByteArray value = rawHeader(it->first);
         if (!value.isEmpty()) {
-            if (it->first.toLower() == "set-cookie")
+            if (qstricmp(it->first.constData(), "set-cookie") == 0)
                 value += "\n";
             else
                 value += ", ";
-- 
1.6.3.3

