From 8b0d6dc32275c081860abdf64d5ec47a54ec7b1c 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 eeb2e6989043d..07befe1844c93 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()) {