Skip to content

Commit

Permalink
Refactor ObjectCache::DeleteUnusedObjects with reverse iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
nagadomi authored and stweil committed May 17, 2021
1 parent d4bcbbd commit 42e4b91
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ccutil/object_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ class ObjectCache {

void DeleteUnusedObjects() {
std::lock_guard<std::mutex> guard(mu_);
for (int i = (int)cache_.size() - 1; i >= 0; i--) {
if (cache_[i].count <= 0) {
delete cache_[i].object;
cache_.erase(cache_.begin() + i);
for (auto it = cache_.rbegin(); it != cache_.rend(); ++it) {
if (it->count <= 0) {
delete it->object;
cache_.erase(std::next(it).base());
}
}
}
Expand Down

0 comments on commit 42e4b91

Please sign in to comment.