diff options
author | Jacques Lucke <jacques@blender.org> | 2022-09-25 18:57:49 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-09-25 18:57:49 +0300 |
commit | 2fd63efd0ea840fa09222ded42ed8494bc2735f8 (patch) | |
tree | d0f6cae6084f346e4f743c74f3bf8d1f485ddf06 /source/blender/editors | |
parent | c6e70e7bacf82b38ca7125d6821713a711489c0b (diff) |
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.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_spreadsheet/spreadsheet_cache.cc | 11 |
1 files changed, 5 insertions, 6 deletions
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) { |