From 91fbe3fe7812af236aa2ea3f76926de5760a7b91 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 9 Mar 2022 16:09:53 +0100 Subject: HTTP2: port to QByteArrayView where it's trivial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nothing serious, just was curious and played around a bit, so might as well merge it. There's much more here that could be done, but I lack the time to do it. Change-Id: Idd4ea09a7a413ed5911ffe16841f3d5c944ec1a5 Reviewed-by: Qt CI Bot Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Timur Pocheptsov --- src/network/access/http2/bitstreams.cpp | 2 +- src/network/access/http2/bitstreams_p.h | 2 +- src/network/access/http2/hpacktable.cpp | 2 +- src/network/access/http2/hpacktable_p.h | 2 +- src/network/access/http2/huffman.cpp | 4 ++-- src/network/access/http2/huffman_p.h | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/network') diff --git a/src/network/access/http2/bitstreams.cpp b/src/network/access/http2/bitstreams.cpp index d22c7cd4ec..1c42b4e478 100644 --- a/src/network/access/http2/bitstreams.cpp +++ b/src/network/access/http2/bitstreams.cpp @@ -99,7 +99,7 @@ void BitOStream::write(quint32 src) } } -void BitOStream::write(const QByteArray &src, bool compressed) +void BitOStream::write(QByteArrayView src, bool compressed) { quint32 byteLen = src.size(); if (compressed && byteLen) { diff --git a/src/network/access/http2/bitstreams_p.h b/src/network/access/http2/bitstreams_p.h index fd1ed9cc30..60ff916c92 100644 --- a/src/network/access/http2/bitstreams_p.h +++ b/src/network/access/http2/bitstreams_p.h @@ -79,7 +79,7 @@ public: // * 32-bit integers // * strings void write(quint32 src); - void write(const QByteArray &src, bool compressed); + void write(QByteArrayView src, bool compressed); quint64 bitLength() const; quint64 byteLength() const; diff --git a/src/network/access/http2/hpacktable.cpp b/src/network/access/http2/hpacktable.cpp index d963cf261b..ec484c7ede 100644 --- a/src/network/access/http2/hpacktable.cpp +++ b/src/network/access/http2/hpacktable.cpp @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE namespace HPack { -HeaderSize entry_size(const QByteArray &name, const QByteArray &value) +HeaderSize entry_size(QByteArrayView name, QByteArrayView value) { // 32 comes from HPACK: // "4.1 Calculating Table Size diff --git a/src/network/access/http2/hpacktable_p.h b/src/network/access/http2/hpacktable_p.h index c9b353a863..196b75f72a 100644 --- a/src/network/access/http2/hpacktable_p.h +++ b/src/network/access/http2/hpacktable_p.h @@ -88,7 +88,7 @@ struct Q_AUTOTEST_EXPORT HeaderField using HeaderSize = QPair; -HeaderSize entry_size(const QByteArray &name, const QByteArray &value); +HeaderSize entry_size(QByteArrayView name, QByteArrayView value); inline HeaderSize entry_size(const HeaderField &entry) { diff --git a/src/network/access/http2/huffman.cpp b/src/network/access/http2/huffman.cpp index 0efea24d2a..8f3e53b13c 100644 --- a/src/network/access/http2/huffman.cpp +++ b/src/network/access/http2/huffman.cpp @@ -381,7 +381,7 @@ void write_huffman_code(BitOStream &outputStream, const CodeEntry &code) // That's from HPACK's specs - we deal with octets. static_assert(std::numeric_limits::digits == 8, "octets expected"); -quint64 huffman_encoded_bit_length(const QByteArray &inputData) +quint64 huffman_encoded_bit_length(QByteArrayView inputData) { quint64 bitLength = 0; for (int i = 0, e = inputData.size(); i < e; ++i) @@ -390,7 +390,7 @@ quint64 huffman_encoded_bit_length(const QByteArray &inputData) return bitLength; } -void huffman_encode_string(const QByteArray &inputData, BitOStream &outputStream) +void huffman_encode_string(QByteArrayView inputData, BitOStream &outputStream) { for (int i = 0, e = inputData.size(); i < e; ++i) { const auto value = uchar(inputData[i]); diff --git a/src/network/access/http2/huffman_p.h b/src/network/access/http2/huffman_p.h index 8c1ca7da6b..e52313f9e7 100644 --- a/src/network/access/http2/huffman_p.h +++ b/src/network/access/http2/huffman_p.h @@ -69,8 +69,8 @@ struct CodeEntry class BitOStream; -quint64 huffman_encoded_bit_length(const QByteArray &inputData); -void huffman_encode_string(const QByteArray &inputData, BitOStream &outputStream); +quint64 huffman_encoded_bit_length(QByteArrayView inputData); +void huffman_encode_string(QByteArrayView inputData, BitOStream &outputStream); // PrefixTable: // Huffman codes with a small bit length -- cgit v1.2.3