[Bf-blender-cvs] [38c9573b238] master: BLI: fix Map.foreach_item method
Jacques Lucke
noreply at git.blender.org
Tue Jun 16 12:16:34 CEST 2020
Commit: 38c9573b2388c37b1df7547a836c790d0f16f02c
Author: Jacques Lucke
Date: Tue Jun 16 12:16:07 2020 +0200
Branches: master
https://developer.blender.org/rB38c9573b2388c37b1df7547a836c790d0f16f02c
BLI: fix Map.foreach_item method
===================================================================
M source/blender/blenlib/BLI_map.hh
M tests/gtests/blenlib/BLI_map_test.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_map.hh b/source/blender/blenlib/BLI_map.hh
index a4c3ee76ca1..ea59579e996 100644
--- a/source/blender/blenlib/BLI_map.hh
+++ b/source/blender/blenlib/BLI_map.hh
@@ -641,7 +641,7 @@ class Map {
*/
template<typename FuncT> void foreach_item(const FuncT &func) const
{
- uint32_t size = this->size();
+ uint32_t size = m_slots.size();
for (uint32_t i = 0; i < size; i++) {
const Slot &slot = m_slots[i];
if (slot.is_occupied()) {
diff --git a/tests/gtests/blenlib/BLI_map_test.cc b/tests/gtests/blenlib/BLI_map_test.cc
index 96e9879abe7..85b2f642654 100644
--- a/tests/gtests/blenlib/BLI_map_test.cc
+++ b/tests/gtests/blenlib/BLI_map_test.cc
@@ -458,6 +458,25 @@ TEST(map, ConstKeysAndValues)
EXPECT_FALSE(map.contains("54"));
}
+TEST(map, ForeachItem)
+{
+ Map<int, int> map;
+ map.add(3, 4);
+ map.add(1, 8);
+
+ Vector<int> keys;
+ Vector<int> values;
+ map.foreach_item([&](int key, int value) {
+ keys.append(key);
+ values.append(value);
+ });
+
+ EXPECT_EQ(keys.size(), 2);
+ EXPECT_EQ(values.size(), 2);
+ EXPECT_EQ(keys.first_index_of(3), values.first_index_of(4));
+ EXPECT_EQ(keys.first_index_of(1), values.first_index_of(8));
+}
+
/**
* Set this to 1 to activate the benchmark. It is disabled by default, because it prints a lot.
*/
More information about the Bf-blender-cvs
mailing list