From 87b650342fbe4dac445295a252349bd3f3d129e7 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 15 May 2023 20:00:28 +0800 Subject: [PATCH] Modernise and improve readability of BandwidthManager::relativeUploadDelayTimerExpired Signed-off-by: Claudio Cambra --- src/libsync/bandwidthmanager.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/libsync/bandwidthmanager.cpp b/src/libsync/bandwidthmanager.cpp index fbf601c29d78e..8845f506bac90 100644 --- a/src/libsync/bandwidthmanager.cpp +++ b/src/libsync/bandwidthmanager.cpp @@ -220,18 +220,21 @@ void BandwidthManager::relativeUploadDelayTimerExpired() _relativeUploadDeviceList.pop_front(); _relativeUploadDeviceList.push_back(_relativeLimitCurrentMeasuredDevice); - _relativeUploadLimitProgressAtMeasuringRestart = (_relativeLimitCurrentMeasuredDevice->_readWithProgress - + _relativeLimitCurrentMeasuredDevice->_read) - / 2; + const auto currentReadWithProgress = _relativeLimitCurrentMeasuredDevice->_readWithProgress; + const auto currentRead = _relativeLimitCurrentMeasuredDevice->_read; + _relativeUploadLimitProgressAtMeasuringRestart = (currentReadWithProgress + currentRead) / 2; + _relativeLimitCurrentMeasuredDevice->setBandwidthLimited(false); _relativeLimitCurrentMeasuredDevice->setChoked(false); // choke all other UploadDevices - Q_FOREACH (UploadDevice *ud, _relativeUploadDeviceList) { - if (ud != _relativeLimitCurrentMeasuredDevice) { - ud->setBandwidthLimited(true); - ud->setChoked(true); + for (const auto uploadDevice : _relativeUploadDeviceList) { + if (uploadDevice == _relativeLimitCurrentMeasuredDevice) { + continue; } + + uploadDevice->setBandwidthLimited(true); + uploadDevice->setChoked(true); } // now we're in measuring state