mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 01:33:07 -07:00
Prevent possible c++11 range-loop container detach
Explicit or implicit calls to begin() and end() cause a non-const container to detach from shared data, ie. to perform a deep-copy to gain a unique copy of the data. That can be a expensive although unneeded operation. In order to assist the developer a copyAsConst function is added. copyAsConst returns a const copy of the object. For lvalues just use qAsConst. It's only available on Qt 5.7.0. But we added also for earlier versions. The developer can always use qAsConst. Intended uses: QString s = ...; for (const auto &ch : qAsConst(s)) process(ch); for (const auto &ch : copyAsConst(funcReturningQString())) process(ch);
This commit is contained in:
parent
98a1c111b9
commit
1a913c502b
7 changed files with 35 additions and 12 deletions
|
@ -55,6 +55,7 @@
|
|||
#endif
|
||||
|
||||
#include "base/bittorrent/torrenthandle.h"
|
||||
#include "base/global.h"
|
||||
|
||||
/**
|
||||
* Converts a path to a string suitable for display.
|
||||
|
@ -128,7 +129,7 @@ bool Utils::Fs::smartRemoveEmptyFolderTree(const QString &path)
|
|||
std::sort(dirList.begin(), dirList.end()
|
||||
, [](const QString &l, const QString &r) { return l.count("/") > r.count("/"); });
|
||||
|
||||
for (const QString &p : dirList) {
|
||||
for (const QString &p : qAsConst(dirList)) {
|
||||
// remove unwanted files
|
||||
for (const QString &f : deleteFilesList) {
|
||||
forceRemove(p + f);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue