Skip to content

Commit

Permalink
Merge pull request #3978 from stweil/sanfix
Browse files Browse the repository at this point in the history
Modernize function ObjectCache::DeleteUnusedObjects (fix issue with s…
  • Loading branch information
egorpugin authored Dec 12, 2022
2 parents b37de16 + 8c34b0d commit 0680ba8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/ccutil/object_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,16 @@ class ObjectCache {

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:
Expand Down

0 comments on commit 0680ba8

Please sign in to comment.