[Bf-blender-cvs] [435698e219b] functions: rename insert to add

Jacques Lucke noreply at git.blender.org
Mon Jul 8 17:57:39 CEST 2019


Commit: 435698e219b4cab014f9baf56d56de67b676acd5
Author: Jacques Lucke
Date:   Mon Jul 8 17:55:07 2019 +0200
Branches: functions
https://developer.blender.org/rB435698e219b4cab014f9baf56d56de67b676acd5

rename insert to add

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

M	source/blender/blenlib/BLI_small_map.hpp
M	source/blender/blenlib/BLI_small_multimap.hpp
M	tests/gtests/blenlib/BLI_small_map_test.cc

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

diff --git a/source/blender/blenlib/BLI_small_map.hpp b/source/blender/blenlib/BLI_small_map.hpp
index 57b440cb5f2..526de350e41 100644
--- a/source/blender/blenlib/BLI_small_map.hpp
+++ b/source/blender/blenlib/BLI_small_map.hpp
@@ -197,9 +197,9 @@ template<typename K, typename V, uint N = 4> class SmallMap {
    * Return true when a new value was inserted, false otherwise.
    */
   template<typename CreateValueFunc, typename ModifyValueFunc>
-  bool insert_or_modify(const K &key,
-                        const CreateValueFunc &create_value,
-                        const ModifyValueFunc &modify_value)
+  bool add_or_modify(const K &key,
+                     const CreateValueFunc &create_value,
+                     const ModifyValueFunc &modify_value)
   {
     uint desired_new_index = m_entries.size();
     uint value_index = m_lookup.add(m_entries.begin(), key, desired_new_index);
diff --git a/source/blender/blenlib/BLI_small_multimap.hpp b/source/blender/blenlib/BLI_small_multimap.hpp
index 27d683223c7..625d9107e7a 100644
--- a/source/blender/blenlib/BLI_small_multimap.hpp
+++ b/source/blender/blenlib/BLI_small_multimap.hpp
@@ -39,34 +39,33 @@ template<typename K, typename V, uint N = 4> class SmallMultiMap {
   bool add(const K &key, const V &value)
   {
     BLI_STATIC_ASSERT(std::is_trivially_destructible<V>::value, "");
-    bool newly_inserted = m_map.insert_or_modify(
-        key,
-        /* Insert new key with value. */
-        [this, &key, &value]() -> Entry {
-          uint offset = m_elements.size();
-          m_elements.append(value);
-          return {offset, 1, 1};
-        },
-        /* Append new value for existing key. */
-        [this, &value](Entry &entry) {
-          if (entry.length < entry.capacity) {
-            m_elements[entry.offset + entry.length] = value;
-            entry.length += 1;
-          }
-          else {
-            uint new_offset = m_elements.size();
-
-            /* Copy the existing elements to the end. */
-            m_elements.extend(entry.get_slice(m_elements));
-            /* Insert the new value and reserve the capacity for this
-             * entry. */
-            m_elements.append_n_times(value, entry.length);
-
-            entry.offset = new_offset;
-            entry.length += 1;
-            entry.capacity *= 2;
-          }
-        });
+    bool newly_inserted = m_map.add_or_modify(key,
+                                              /* Insert new key with value. */
+                                              [this, &key, &value]() -> Entry {
+                                                uint offset = m_elements.size();
+                                                m_elements.append(value);
+                                                return {offset, 1, 1};
+                                              },
+                                              /* Append new value for existing key. */
+                                              [this, &value](Entry &entry) {
+                                                if (entry.length < entry.capacity) {
+                                                  m_elements[entry.offset + entry.length] = value;
+                                                  entry.length += 1;
+                                                }
+                                                else {
+                                                  uint new_offset = m_elements.size();
+
+                                                  /* Copy the existing elements to the end. */
+                                                  m_elements.extend(entry.get_slice(m_elements));
+                                                  /* Insert the new value and reserve the capacity
+                                                   * for this entry. */
+                                                  m_elements.append_n_times(value, entry.length);
+
+                                                  entry.offset = new_offset;
+                                                  entry.length += 1;
+                                                  entry.capacity *= 2;
+                                                }
+                                              });
     return newly_inserted;
   }
 
diff --git a/tests/gtests/blenlib/BLI_small_map_test.cc b/tests/gtests/blenlib/BLI_small_map_test.cc
index 366ce770070..e685e5e45f0 100644
--- a/tests/gtests/blenlib/BLI_small_map_test.cc
+++ b/tests/gtests/blenlib/BLI_small_map_test.cc
@@ -194,8 +194,8 @@ TEST(small_map, InsertOrModify)
   IntFloatMap map;
   auto create_func = []() { return 10.0f; };
   auto modify_func = [](float &value) { value += 5; };
-  EXPECT_TRUE(map.insert_or_modify(1, create_func, modify_func));
+  EXPECT_TRUE(map.add_or_modify(1, create_func, modify_func));
   EXPECT_EQ(map.lookup(1), 10.0f);
-  EXPECT_FALSE(map.insert_or_modify(1, create_func, modify_func));
+  EXPECT_FALSE(map.add_or_modify(1, create_func, modify_func));
   EXPECT_EQ(map.lookup(1), 15.0f);
 }



More information about the Bf-blender-cvs mailing list