[Bf-blender-cvs] [f073f232cfe] functions: improve map method names

Jacques Lucke noreply at git.blender.org
Wed Aug 14 11:53:56 CEST 2019


Commit: f073f232cfef405eb278c83fd1d713dc3204aafe
Author: Jacques Lucke
Date:   Wed Aug 14 11:53:08 2019 +0200
Branches: functions
https://developer.blender.org/rBf073f232cfef405eb278c83fd1d713dc3204aafe

improve map method names

===================================================================

M	source/blender/blenlib/BLI_map.hpp
M	source/blender/functions/functions/auto_vectorization.cpp
M	tests/gtests/blenlib/BLI_map_test.cc

===================================================================

diff --git a/source/blender/blenlib/BLI_map.hpp b/source/blender/blenlib/BLI_map.hpp
index c24f694ddbe..a1852d613d6 100644
--- a/source/blender/blenlib/BLI_map.hpp
+++ b/source/blender/blenlib/BLI_map.hpp
@@ -167,7 +167,7 @@ template<typename K, typename V, uint N = 4> class Map {
    * Return a reference to the value corresponding to the key.
    * If the key does not exist yet, insert the given key-value-pair first.
    */
-  V &lookup_ref_or_insert(const K &key, V initial_value)
+  V &lookup_or_add(const K &key, V initial_value)
   {
     V *ptr = this->lookup_ptr(key);
     if (ptr != nullptr) {
@@ -183,7 +183,7 @@ template<typename K, typename V, uint N = 4> class Map {
    * key-value pair.
    */
   template<typename CreateValueFunc>
-  V &lookup_ref_or_insert_func(const K &key, const CreateValueFunc &create_value)
+  V &lookup_or_add_func(const K &key, const CreateValueFunc &create_value)
   {
     V *ptr = this->lookup_ptr(key);
     if (ptr != nullptr) {
diff --git a/source/blender/functions/functions/auto_vectorization.cpp b/source/blender/functions/functions/auto_vectorization.cpp
index aaf5f1de988..a55a6a070e5 100644
--- a/source/blender/functions/functions/auto_vectorization.cpp
+++ b/source/blender/functions/functions/auto_vectorization.cpp
@@ -506,7 +506,7 @@ SharedFunction to_vectorized_function__with_cache(
   static VectorizeCacheMap &cache = get_vectorized_function_cache();
 
   AutoVectorizationInput cache_key(original_fn, vectorized_inputs_mask, empty_list_value_builders);
-  return cache.lookup_ref_or_insert_func(cache_key, [&]() {
+  return cache.lookup_or_add_func(cache_key, [&]() {
     return to_vectorized_function_internal(
         original_fn, vectorized_inputs_mask, empty_list_value_builders);
   });
diff --git a/tests/gtests/blenlib/BLI_map_test.cc b/tests/gtests/blenlib/BLI_map_test.cc
index c61372fe41d..12206109275 100644
--- a/tests/gtests/blenlib/BLI_map_test.cc
+++ b/tests/gtests/blenlib/BLI_map_test.cc
@@ -87,13 +87,13 @@ TEST(map, PopItemMany)
   }
 }
 
-TEST(map, LookupRefOrInsert)
+TEST(map, LookupOrAdd)
 {
   IntFloatMap map;
-  float &value = map.lookup_ref_or_insert(3, 5.0f);
+  float &value = map.lookup_or_add(3, 5.0f);
   EXPECT_EQ(value, 5.0f);
   value += 1;
-  value = map.lookup_ref_or_insert(3, 5.0f);
+  value = map.lookup_or_add(3, 5.0f);
   EXPECT_EQ(value, 6.0f);
 }
 
@@ -170,23 +170,23 @@ float return_42()
   return 42.0f;
 }
 
-TEST(map, LookupOrInsertFunc_SeparateFunction)
+TEST(map, LookupOrAddFunc_SeparateFunction)
 {
   IntFloatMap map;
-  EXPECT_EQ(map.lookup_ref_or_insert_func(0, return_42), 42.0f);
+  EXPECT_EQ(map.lookup_or_add_func(0, return_42), 42.0f);
   EXPECT_EQ(map.lookup(0), 42);
 }
 
-TEST(map, LookupOrInsertFunc_Lambdas)
+TEST(map, LookupOrAddFunc_Lambdas)
 {
   IntFloatMap map;
   auto lambda1 = []() { return 11.0f; };
-  EXPECT_EQ(map.lookup_ref_or_insert_func(0, lambda1), 11.0f);
+  EXPECT_EQ(map.lookup_or_add_func(0, lambda1), 11.0f);
   auto lambda2 = []() { return 20.0f; };
-  EXPECT_EQ(map.lookup_ref_or_insert_func(1, lambda2), 20.0f);
+  EXPECT_EQ(map.lookup_or_add_func(1, lambda2), 20.0f);
 
-  EXPECT_EQ(map.lookup_ref_or_insert_func(0, lambda2), 11.0f);
-  EXPECT_EQ(map.lookup_ref_or_insert_func(1, lambda1), 20.0f);
+  EXPECT_EQ(map.lookup_or_add_func(0, lambda2), 11.0f);
+  EXPECT_EQ(map.lookup_or_add_func(1, lambda1), 20.0f);
 }
 
 TEST(map, InsertOrModify)



More information about the Bf-blender-cvs mailing list