summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Pattyn <pattyn.kurt@gmail.com>2013-11-03 13:28:14 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-03 13:28:41 +0100
commita4fe430cad228f9aa5c2a8a67aed8345a3cababd (patch)
tree52e651da3de471da136c312ac85afd3978cc46fd
parent66cae36228e44f83a0393ab0f6062627760d1d27 (diff)
downloadqtwebsockets-a4fe430cad228f9aa5c2a8a67aed8345a3cababd.tar.gz
Improve speed of masking
Change-Id: Ieb1b28ac2ae37453da5b365587b8ab0e183ae269 Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
-rw-r--r--src/websockets/qwebsocketprotocol_p.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/websockets/qwebsocketprotocol_p.cpp b/src/websockets/qwebsocketprotocol_p.cpp
index c00711b..09e717f 100644
--- a/src/websockets/qwebsocketprotocol_p.cpp
+++ b/src/websockets/qwebsocketprotocol_p.cpp
@@ -166,20 +166,21 @@ void mask(QByteArray *payload, quint32 maskingKey)
void mask(char *payload, quint64 size, quint32 maskingKey)
{
quint32 *payloadData = reinterpret_cast<quint32 *>(payload);
- const quint32 numIterations = static_cast<quint32>(size / sizeof(quint32));
- const quint32 remainder = size % sizeof(quint32);
- quint32 i;
- for (i = 0; i < numIterations; ++i)
+ quint32 numIterations = static_cast<quint32>(size / sizeof(quint32));
+ quint32 remainder = size % sizeof(quint32);
+ const quint32 offset = numIterations * sizeof(quint32);
+ //maskingKey = qToBigEndian<quint32>(maskingKey);
+ while (numIterations--)
{
- *(payloadData + i) ^= maskingKey;
+ *payloadData++ ^= maskingKey;
}
- if (remainder)
+ if (remainder) //remainder is < 4
{
- const quint32 offset = i * static_cast<quint32>(sizeof(quint32));
const char *mask = reinterpret_cast<const char *>(&maskingKey);
- for (quint32 i = 0; i < remainder; ++i)
+ payload += offset;
+ while (remainder--)
{
- *(payload + offset + i) ^= (mask[(i + offset) % 4]);
+ *payload++ ^= *mask++;
}
}
}