Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-03-25 17:31:09 +0300
committerJacques Lucke <jacques@blender.org>2021-03-25 18:01:41 +0300
commit9b426269189ce00add24e48c951c45aca01f2076 (patch)
tree5c62976de44a0703fe39b251d91ea65ccfae098f
parent56df673be271c10200d758e0b0e891750103f8d6 (diff)
BLI: fix Set.lookup_key_or_add
-rw-r--r--source/blender/blenlib/BLI_set.hh2
-rw-r--r--source/blender/blenlib/tests/BLI_set_test.cc4
2 files changed, 4 insertions, 2 deletions
diff --git a/source/blender/blenlib/BLI_set.hh b/source/blender/blenlib/BLI_set.hh
index fef657b2d8f..a8ccf957f6c 100644
--- a/source/blender/blenlib/BLI_set.hh
+++ b/source/blender/blenlib/BLI_set.hh
@@ -788,6 +788,8 @@ class Set {
template<typename ForwardKey>
const Key &lookup_key_or_add__impl(ForwardKey &&key, const uint64_t hash)
{
+ this->ensure_can_add();
+
SET_SLOT_PROBING_BEGIN (hash, slot) {
if (slot.contains(key, is_equal_, hash)) {
return *slot.key();
diff --git a/source/blender/blenlib/tests/BLI_set_test.cc b/source/blender/blenlib/tests/BLI_set_test.cc
index 56f1d57e4ae..3a4733a218f 100644
--- a/source/blender/blenlib/tests/BLI_set_test.cc
+++ b/source/blender/blenlib/tests/BLI_set_test.cc
@@ -456,8 +456,8 @@ TEST(set, LookupKeyPtr)
TEST(set, LookupKeyOrAdd)
{
Set<MyKeyType> set;
- set.add({1, 10});
- set.add({2, 20});
+ set.lookup_key_or_add({1, 10});
+ set.lookup_key_or_add({2, 20});
EXPECT_EQ(set.size(), 2);
EXPECT_EQ(set.lookup_key_or_add({2, 40}).attached_data, 20);
EXPECT_EQ(set.size(), 2);