From a786404036990c595e25122fae5f710f12bc397b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 4 Apr 2024 10:39:06 +0200 Subject: [PATCH] NetworkReply[wasm]: simplify some buffer passing It was always passing a QByteArray to a const char * argument, with the size along with it. That was immediately converted back to a QByteArray. Instead, just pass the byte array which anyway knows its size. Needed for a followup commit Change-Id: I821d419adcb600456826dde67fb92ecad11cb290 Reviewed-by: Edward Welbourne --- src/network/access/qnetworkreplywasmimpl.cpp | 9 +++++---- src/network/access/qnetworkreplywasmimpl_p.h | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/network/access/qnetworkreplywasmimpl.cpp b/src/network/access/qnetworkreplywasmimpl.cpp index d8190434ccf..741502dc9b8 100644 --- a/src/network/access/qnetworkreplywasmimpl.cpp +++ b/src/network/access/qnetworkreplywasmimpl.cpp @@ -318,10 +318,11 @@ void QNetworkReplyWasmImplPrivate::emitDataReadProgress(qint64 bytesReceived, qi emit q->downloadProgress(bytesReceived, bytesTotal); } -void QNetworkReplyWasmImplPrivate::dataReceived(const QByteArray &buffer, int bufferSize) +void QNetworkReplyWasmImplPrivate::dataReceived(const QByteArray &buffer) { Q_Q(QNetworkReplyWasmImpl); + const qsizetype bufferSize = buffer.size(); if (bufferSize > 0) q->setReadBufferSize(bufferSize); @@ -334,7 +335,7 @@ void QNetworkReplyWasmImplPrivate::dataReceived(const QByteArray &buffer, int bu totalDownloadSize = downloadBufferCurrentSize; - downloadBuffer.append(buffer, bufferSize); + downloadBuffer.append(buffer); emit q->readyRead(); } @@ -476,7 +477,7 @@ void QNetworkReplyWasmImplPrivate::downloadSucceeded(emscripten_fetch_t *fetch) if (reply) { if (reply->state != QNetworkReplyPrivate::Aborted) { QByteArray buffer(fetch->data, fetch->numBytes); - reply->dataReceived(buffer, buffer.size()); + reply->dataReceived(buffer); QByteArray statusText(fetch->statusText); reply->setStatusCode(fetch->status, statusText); reply->setReplyFinished(); @@ -539,7 +540,7 @@ void QNetworkReplyWasmImplPrivate::downloadFailed(emscripten_fetch_t *fetch) else reasonStr = QString::fromUtf8(fetch->statusText); QByteArray buffer(fetch->data, fetch->numBytes); - reply->dataReceived(buffer, buffer.size()); + reply->dataReceived(buffer); QByteArray statusText(fetch->statusText); reply->setStatusCode(fetch->status, statusText); reply->emitReplyError(reply->statusCodeFromHttp(fetch->status, reply->request.url()), reasonStr); diff --git a/src/network/access/qnetworkreplywasmimpl_p.h b/src/network/access/qnetworkreplywasmimpl_p.h index d8c814621b9..ae167799d73 100644 --- a/src/network/access/qnetworkreplywasmimpl_p.h +++ b/src/network/access/qnetworkreplywasmimpl_p.h @@ -57,7 +57,7 @@ public: Q_PRIVATE_SLOT(d_func(), void emitReplyError(QNetworkReply::NetworkError errorCode, const QString &errorString)) Q_PRIVATE_SLOT(d_func(), void emitDataReadProgress(qint64 done, qint64 total)) - Q_PRIVATE_SLOT(d_func(), void dataReceived(char *buffer, int bufferSize)) + Q_PRIVATE_SLOT(d_func(), void dataReceived(const QByteArray &buffer)) private: QByteArray methodName() const; @@ -75,7 +75,7 @@ public: void emitReplyError(QNetworkReply::NetworkError errorCode, const QString &); void emitDataReadProgress(qint64 done, qint64 total); - void dataReceived(const QByteArray &buffer, int bufferSize); + void dataReceived(const QByteArray &buffer); void headersReceived(const QByteArray &buffer); void setStatusCode(int status, const QByteArray &statusText);