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() {
std::lock_guard<std::mutex> guard(mu_);
for (auto it = cache_.rbegin(); it != cache_.rend(); ++it) {
if (it->count <= 0) {
delete it->object;
cache_.erase(std::next(it).base());
}
cache_.erase(std::remove_if(cache_.begin(), cache_.end(),
[](const ReferenceCount &it) {
if (it.count <= 0) {
delete it.object;
return true;
} else {
return false;
}
}),
cache_.end());
}
private: