[Bf-blender-cvs] [0fe5be35255] master: Cleanup: return const reference instead of copy

Jacques Lucke noreply at git.blender.org
Thu Feb 18 12:40:34 CET 2021


Commit: 0fe5be352558c487e24724fca4c2cb9f53a724e6
Author: Jacques Lucke
Date:   Thu Feb 18 12:40:27 2021 +0100
Branches: master
https://developer.blender.org/rB0fe5be352558c487e24724fca4c2cb9f53a724e6

Cleanup: return const reference instead of copy

There isn't really a reason for why this has to return a copy of
the data instead of a reference.

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

M	source/blender/functions/FN_generic_value_map.hh
M	source/blender/nodes/NOD_geometry_exec.hh

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

diff --git a/source/blender/functions/FN_generic_value_map.hh b/source/blender/functions/FN_generic_value_map.hh
index a9f2dc8a868..68cb945f1af 100644
--- a/source/blender/functions/FN_generic_value_map.hh
+++ b/source/blender/functions/FN_generic_value_map.hh
@@ -104,14 +104,12 @@ template<typename Key> class GValueMap {
     return return_value;
   }
 
-  template<typename T, typename ForwardKey> T lookup(const ForwardKey &key) const
+  template<typename T, typename ForwardKey> const T &lookup(const ForwardKey &key) const
   {
     GMutablePointer value = values_.lookup_as(key);
-    const CPPType &type = *value.type();
-    BLI_assert(type.is<T>());
-    T return_value;
-    type.copy_to_initialized(value.get(), &return_value);
-    return return_value;
+    BLI_assert(value.is_type<T>());
+    BLI_assert(value.get() != nullptr);
+    return *(const T *)value.get();
   }
 
   template<typename ForwardKey> bool contains(const ForwardKey &key) const
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index d5fd3ff0abb..e648d77337b 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -133,11 +133,8 @@ class GeoNodeExecParams {
 
   /**
    * Get the input value for the input socket with the given identifier.
-   *
-   * This makes a copy of the value, which is fine for most types but should be avoided for
-   * geometry sets.
    */
-  template<typename T> T get_input(StringRef identifier) const
+  template<typename T> const T &get_input(StringRef identifier) const
   {
 #ifdef DEBUG
     this->check_extract_input(identifier, &CPPType::get<T>());



More information about the Bf-blender-cvs mailing list