Merge pull request #3978 from stweil/sanfix

Modernize function ObjectCache::DeleteUnusedObjects (fix issue with s…
This commit is contained in:
Egor Pugin 2022-12-12 17:56:42 +03:00 committed by GitHub
commit 0680ba870e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,12 +96,16 @@ public:
void DeleteUnusedObjects() { void DeleteUnusedObjects() {
std::lock_guard<std::mutex> guard(mu_); std::lock_guard<std::mutex> guard(mu_);
for (auto it = cache_.rbegin(); it != cache_.rend(); ++it) { cache_.erase(std::remove_if(cache_.begin(), cache_.end(),
if (it->count <= 0) { [](const ReferenceCount &it) {
delete it->object; if (it.count <= 0) {
cache_.erase(std::next(it).base()); delete it.object;
} return true;
} } else {
return false;
}
}),
cache_.end());
} }
private: private: