[Bf-blender-cvs] [26bc584e012] master: Cleanup: Better const correctness for DEG_get_eval_flags_for_id

Sergey Sharybin noreply at git.blender.org
Thu May 5 15:56:58 CEST 2022


Commit: 26bc584e01278927ada72b040e3b4e5ab89927fe
Author: Sergey Sharybin
Date:   Thu May 5 15:52:57 2022 +0200
Branches: master
https://developer.blender.org/rB26bc584e01278927ada72b040e3b4e5ab89927fe

Cleanup: Better const correctness for DEG_get_eval_flags_for_id

The ID is not modified by this function, so it can be const.

Needed to tweak const correctness for original ID accessor as
well. Additionally, did the same for accessor of evaluated ID
for symmetry.

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

M	source/blender/depsgraph/DEG_depsgraph_query.h
M	source/blender/depsgraph/intern/depsgraph_query.cc

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

diff --git a/source/blender/depsgraph/DEG_depsgraph_query.h b/source/blender/depsgraph/DEG_depsgraph_query.h
index ade75fa2f6f..12663e74d24 100644
--- a/source/blender/depsgraph/DEG_depsgraph_query.h
+++ b/source/blender/depsgraph/DEG_depsgraph_query.h
@@ -64,7 +64,7 @@ bool DEG_id_type_any_updated(const struct Depsgraph *depsgraph);
 bool DEG_id_type_any_exists(const struct Depsgraph *depsgraph, short id_type);
 
 /** Get additional evaluation flags for the given ID. */
-uint32_t DEG_get_eval_flags_for_id(const struct Depsgraph *graph, struct ID *id);
+uint32_t DEG_get_eval_flags_for_id(const struct Depsgraph *graph, const struct ID *id);
 
 /** Get additional mesh CustomData_MeshMasks flags for the given object. */
 void DEG_get_customdata_mask_for_object(const struct Depsgraph *graph,
diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc b/source/blender/depsgraph/intern/depsgraph_query.cc
index fd569599b8b..015fa341e68 100644
--- a/source/blender/depsgraph/intern/depsgraph_query.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query.cc
@@ -32,6 +32,49 @@
 #include "intern/eval/deg_eval_copy_on_write.h"
 #include "intern/node/deg_node_id.h"
 
+namespace blender::deg {
+
+const ID *get_original_id(const ID *id)
+{
+  if (id == nullptr) {
+    return nullptr;
+  }
+  if (id->orig_id == nullptr) {
+    return id;
+  }
+  BLI_assert((id->tag & LIB_TAG_COPIED_ON_WRITE) != 0);
+  return (ID *)id->orig_id;
+}
+
+ID *get_original_id(ID *id)
+{
+  const ID *const_id = id;
+  return const_cast<ID *>(get_original_id(const_id));
+}
+
+const ID *get_evaluated_id(const Depsgraph *deg_graph, const ID *id)
+{
+  if (id == nullptr) {
+    return nullptr;
+  }
+  /* TODO(sergey): This is a duplicate of Depsgraph::get_cow_id(),
+   * but here we never do assert, since we don't know nature of the
+   * incoming ID data-block. */
+  const IDNode *id_node = deg_graph->find_id_node(id);
+  if (id_node == nullptr) {
+    return id;
+  }
+  return id_node->id_cow;
+}
+
+ID *get_evaluated_id(const Depsgraph *deg_graph, ID *id)
+{
+  const ID *const_id = id;
+  return const_cast<ID *>(get_evaluated_id(deg_graph, const_id));
+}
+
+}  // namespace blender::deg
+
 namespace deg = blender::deg;
 
 struct Scene *DEG_get_input_scene(const Depsgraph *graph)
@@ -90,7 +133,7 @@ bool DEG_id_type_any_exists(const Depsgraph *depsgraph, short id_type)
   return deg_graph->id_type_exist[BKE_idtype_idcode_to_index(id_type)] != 0;
 }
 
-uint32_t DEG_get_eval_flags_for_id(const Depsgraph *graph, ID *id)
+uint32_t DEG_get_eval_flags_for_id(const Depsgraph *graph, const ID *id)
 {
   if (graph == nullptr) {
     /* Happens when converting objects to mesh from a python script
@@ -102,7 +145,7 @@ uint32_t DEG_get_eval_flags_for_id(const Depsgraph *graph, ID *id)
   }
 
   const deg::Depsgraph *deg_graph = reinterpret_cast<const deg::Depsgraph *>(graph);
-  const deg::IDNode *id_node = deg_graph->find_id_node(DEG_get_original_id(id));
+  const deg::IDNode *id_node = deg_graph->find_id_node(deg::get_original_id(id));
   if (id_node == nullptr) {
     /* TODO(sergey): Does it mean we need to check set scene? */
     return 0;
@@ -171,18 +214,7 @@ Object *DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
 
 ID *DEG_get_evaluated_id(const Depsgraph *depsgraph, ID *id)
 {
-  if (id == nullptr) {
-    return nullptr;
-  }
-  /* TODO(sergey): This is a duplicate of Depsgraph::get_cow_id(),
-   * but here we never do assert, since we don't know nature of the
-   * incoming ID data-block. */
-  const deg::Depsgraph *deg_graph = (const deg::Depsgraph *)depsgraph;
-  const deg::IDNode *id_node = deg_graph->find_id_node(id);
-  if (id_node == nullptr) {
-    return id;
-  }
-  return id_node->id_cow;
+  return deg::get_evaluated_id(reinterpret_cast<const deg::Depsgraph *>(depsgraph), id);
 }
 
 void DEG_get_evaluated_rna_pointer(const Depsgraph *depsgraph,
@@ -249,14 +281,7 @@ Object *DEG_get_original_object(Object *object)
 
 ID *DEG_get_original_id(ID *id)
 {
-  if (id == nullptr) {
-    return nullptr;
-  }
-  if (id->orig_id == nullptr) {
-    return id;
-  }
-  BLI_assert((id->tag & LIB_TAG_COPIED_ON_WRITE) != 0);
-  return (ID *)id->orig_id;
+  return deg::get_original_id(id);
 }
 
 bool DEG_is_original_id(const ID *id)



More information about the Bf-blender-cvs mailing list