From 2fd63efd0ea840fa09222ded42ed8494bc2735f8 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Sun, 25 Sep 2022 17:57:49 +0200 Subject: BLI: simplify removing elements from containers with predicate Previously removing elements based on a predicate was a bit cumbersome, especially for hash tables. Now there is a new `remove_if` method in some data structures which is similar to `std::erase_if`. We could consider adding `blender::erase_if` in the future to more closely mimic the standard library, but for now this is using the api design of the surrounding code is used. --- source/blender/editors/space_spreadsheet/spreadsheet_cache.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'source/blender/editors/space_spreadsheet') diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_cache.cc b/source/blender/editors/space_spreadsheet/spreadsheet_cache.cc index 931a00ab583..752a7451964 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_cache.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_cache.cc @@ -45,12 +45,11 @@ void SpreadsheetCache::set_all_unused() void SpreadsheetCache::remove_all_unused() { /* First remove the keys from the map and free the values. */ - for (auto it = cache_map_.keys().begin(); it != cache_map_.keys().end(); ++it) { - const Key &key = *it; - if (!key.is_used) { - cache_map_.remove(it); - } - } + cache_map_.remove_if([&](auto item) { + const Key &key = item.key; + return !key.is_used; + }); + /* Then free the keys. */ for (int i = 0; i < keys_.size();) { if (keys_[i]->is_used) { -- cgit v1.2.3