From d886b41db632809b6b675c836cf00526609c9495 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sun, 14 May 2023 21:45:34 +0200 Subject: [PATCH] fix: remove else after return --- src/common/NetworkPrivate.cpp | 84 ++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/src/common/NetworkPrivate.cpp b/src/common/NetworkPrivate.cpp index 622091f932d..f0a74ed5ab4 100644 --- a/src/common/NetworkPrivate.cpp +++ b/src/common/NetworkPrivate.cpp @@ -77,7 +77,7 @@ void loadUncached(std::shared_ptr &&data) DebugCount::increase("http request started"); NetworkRequester requester; - NetworkWorker *worker = new NetworkWorker; + auto *worker = new NetworkWorker; worker->moveToThread(&NetworkManager::workerThread); @@ -245,12 +245,16 @@ void loadUncached(std::shared_ptr &&data) if (data->onSuccess_) { if (data->executeConcurrently_) + { QtConcurrent::run([onSuccess = std::move(data->onSuccess_), result = std::move(result)] { onSuccess(result); }); + } else + { data->onSuccess_(result); + } } // log("finished {}", data->request_.url().toString()); @@ -330,64 +334,62 @@ void loadCached(std::shared_ptr &&data) loadUncached(std::move(data)); return; } - else + + // XXX: check if bytes is empty? + QByteArray bytes = cachedFile.readAll(); + NetworkResult result(bytes, 200); + + qCDebug(chatterinoHTTP) + << QString("%1 [CACHED] 200 %2") + .arg(networkRequestTypes.at(int(data->requestType_)), + data->request_.url().toString()); + if (data->onSuccess_) { - // XXX: check if bytes is empty? - QByteArray bytes = cachedFile.readAll(); - NetworkResult result(bytes, 200); - - qCDebug(chatterinoHTTP) - << QString("%1 [CACHED] 200 %2") - .arg(networkRequestTypes.at(int(data->requestType_)), - data->request_.url().toString()); - if (data->onSuccess_) + if (data->executeConcurrently_ || isGuiThread()) { - if (data->executeConcurrently_ || isGuiThread()) + // XXX: If outcome is Failure, we should invalidate the cache file + // somehow/somewhere + /*auto outcome =*/ + if (data->hasCaller_ && !data->caller_.get()) { - // XXX: If outcome is Failure, we should invalidate the cache file - // somehow/somewhere - /*auto outcome =*/ + return; + } + data->onSuccess_(result); + } + else + { + postToThread([data, result]() { if (data->hasCaller_ && !data->caller_.get()) { return; } - data->onSuccess_(result); - } - else - { - postToThread([data, result]() { - if (data->hasCaller_ && !data->caller_.get()) - { - return; - } - data->onSuccess_(result); - }); - } + data->onSuccess_(result); + }); } + } - if (data->finally_) + if (data->finally_) + { + if (data->executeConcurrently_ || isGuiThread()) { - if (data->executeConcurrently_ || isGuiThread()) + if (data->hasCaller_ && !data->caller_.get()) { + return; + } + + data->finally_(); + } + else + { + postToThread([data]() { if (data->hasCaller_ && !data->caller_.get()) { return; } data->finally_(); - } - else - { - postToThread([data]() { - if (data->hasCaller_ && !data->caller_.get()) - { - return; - } - - data->finally_(); - }); - } + }); } } }