From fdb20b62e6c45af211705a98d9a8afac1d69e66f Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Wed, 11 Oct 2023 14:24:22 +0200 Subject: [PATCH] avoid for loops detaching the container when uneeded Signed-off-by: Matthieu Gallien --- src/libsync/syncengine.cpp | 2 +- test/testsecurefiledrop.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 1fbaf01314713..7d7badda0de95 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -811,7 +811,7 @@ void SyncEngine::slotDiscoveryFinished() } if (_discoveryPhase->_hasDownloadRemovedItems && _discoveryPhase->_hasUploadErrorItems) { - for (const auto &item : _syncItems) { + for (const auto &item : qAsConst(_syncItems)) { if (item->_instruction == CSYNC_INSTRUCTION_ERROR && item->_direction == SyncFileItem::Up) { item->_instruction = CSYNC_INSTRUCTION_IGNORE; } diff --git a/test/testsecurefiledrop.cpp b/test/testsecurefiledrop.cpp index d0b7020f939a2..96d71da2d9ec3 100644 --- a/test/testsecurefiledrop.cpp +++ b/test/testsecurefiledrop.cpp @@ -142,7 +142,8 @@ private slots: bool isAnyFileDropFileMissing = false; - for (const auto &key : metadata->fileDrop().keys()) { + const auto allKeys = metadata->fileDrop().keys(); + for (const auto &key : allKeys) { if (std::find_if(metadata->files().constBegin(), metadata->files().constEnd(), [&key](const EncryptedFile &encryptedFile) { return encryptedFile.encryptedFilename == key; }) == metadata->files().constEnd()) {