[Bf-blender-cvs] [52b8d668f4d] master: Depsgraph: use blender::Map instead of std::map

Jacques Lucke noreply at git.blender.org
Thu Jun 18 18:19:47 CEST 2020


Commit: 52b8d668f4d3d0a841313b678027a2d6af2fbc37
Author: Jacques Lucke
Date:   Thu Jun 18 18:16:51 2020 +0200
Branches: master
https://developer.blender.org/rB52b8d668f4d3d0a841313b678027a2d6af2fbc37

Depsgraph: use blender::Map instead of std::map

We decided to use our own map data structure in general for better
readability and performance.

Reviewers: sergey

Differential Revision: https://developer.blender.org/D7987

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

M	source/blender/depsgraph/intern/builder/deg_builder_cache.cc
M	source/blender/depsgraph/intern/builder/deg_builder_cache.h
M	source/blender/depsgraph/intern/builder/deg_builder_map.cc
M	source/blender/depsgraph/intern/builder/deg_builder_map.h
M	source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M	source/blender/depsgraph/intern/depsgraph_type.h
M	source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_modifier.cc
M	source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_modifier.h
M	source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_object.cc
M	source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_object.h
M	source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_pose.h
M	source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_sequencer.cc
M	source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_sequencer.h

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

diff --git a/source/blender/depsgraph/intern/builder/deg_builder_cache.cc b/source/blender/depsgraph/intern/builder/deg_builder_cache.cc
index 104676f7ab6..62d9118cbc0 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_cache.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_cache.cc
@@ -155,21 +155,16 @@ DepsgraphBuilderCache::DepsgraphBuilderCache()
 
 DepsgraphBuilderCache::~DepsgraphBuilderCache()
 {
-  for (AnimatedPropertyStorageMap::value_type &iter : animated_property_storage_map_) {
-    AnimatedPropertyStorage *animated_property_storage = iter.second;
+  for (AnimatedPropertyStorage *animated_property_storage :
+       animated_property_storage_map_.values()) {
     OBJECT_GUARDED_DELETE(animated_property_storage, AnimatedPropertyStorage);
   }
 }
 
 AnimatedPropertyStorage *DepsgraphBuilderCache::ensureAnimatedPropertyStorage(ID *id)
 {
-  AnimatedPropertyStorageMap::iterator it = animated_property_storage_map_.find(id);
-  if (it != animated_property_storage_map_.end()) {
-    return it->second;
-  }
-  AnimatedPropertyStorage *animated_property_storage = OBJECT_GUARDED_NEW(AnimatedPropertyStorage);
-  animated_property_storage_map_.insert(make_pair(id, animated_property_storage));
-  return animated_property_storage;
+  return animated_property_storage_map_.lookup_or_add_cb(
+      id, []() { return OBJECT_GUARDED_NEW(AnimatedPropertyStorage); });
 }
 
 AnimatedPropertyStorage *DepsgraphBuilderCache::ensureInitializedAnimatedPropertyStorage(ID *id)
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_cache.h b/source/blender/depsgraph/intern/builder/deg_builder_cache.h
index bb4e1f5c96a..531d1664281 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_cache.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_cache.h
@@ -45,8 +45,6 @@ class AnimatedPropertyID {
   AnimatedPropertyID(ID *id, StructRNA *type, void *data, const char *property_name);
 
   uint32_t hash() const;
-
-  bool operator<(const AnimatedPropertyID &other) const;
   friend bool operator==(const AnimatedPropertyID &a, const AnimatedPropertyID &b);
 
   /* Corresponds to PointerRNA.data. */
@@ -73,8 +71,6 @@ class AnimatedPropertyStorage {
   Set<AnimatedPropertyID> animated_properties_set;
 };
 
-typedef map<ID *, AnimatedPropertyStorage *> AnimatedPropertyStorageMap;
-
 /* Cached data which can be re-used by multiple builders. */
 class DepsgraphBuilderCache {
  public:
@@ -100,7 +96,7 @@ class DepsgraphBuilderCache {
     return animated_property_storage->isPropertyAnimated(args...);
   }
 
-  AnimatedPropertyStorageMap animated_property_storage_map_;
+  Map<ID *, AnimatedPropertyStorage *> animated_property_storage_map_;
 };
 
 }  // namespace DEG
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_map.cc b/source/blender/depsgraph/intern/builder/deg_builder_map.cc
index 4bca4f037b0..d0bebd8b10a 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_map.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_map.cc
@@ -42,33 +42,20 @@ bool BuilderMap::checkIsBuilt(ID *id, int tag) const
 
 void BuilderMap::tagBuild(ID *id, int tag)
 {
-  IDTagMap::iterator it = id_tags_.find(id);
-  if (it == id_tags_.end()) {
-    id_tags_.insert(make_pair(id, tag));
-    return;
-  }
-  it->second |= tag;
+  id_tags_.lookup_or_add(id, 0) |= tag;
 }
 
 bool BuilderMap::checkIsBuiltAndTag(ID *id, int tag)
 {
-  IDTagMap::iterator it = id_tags_.find(id);
-  if (it == id_tags_.end()) {
-    id_tags_.insert(make_pair(id, tag));
-    return false;
-  }
-  const bool result = (it->second & tag) == tag;
-  it->second |= tag;
+  int &id_tag = id_tags_.lookup_or_add(id, 0);
+  const bool result = (id_tag & tag) == tag;
+  id_tag |= tag;
   return result;
 }
 
 int BuilderMap::getIDTag(ID *id) const
 {
-  IDTagMap::const_iterator it = id_tags_.find(id);
-  if (it == id_tags_.end()) {
-    return 0;
-  }
-  return it->second;
+  return id_tags_.lookup_default(id, 0);
 }
 
 }  // namespace DEG
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_map.h b/source/blender/depsgraph/intern/builder/deg_builder_map.h
index 65b493e2467..54561a0c3d2 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_map.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_map.h
@@ -75,8 +75,7 @@ class BuilderMap {
  protected:
   int getIDTag(ID *id) const;
 
-  typedef map<ID *, int> IDTagMap;
-  IDTagMap id_tags_;
+  Map<ID *, int> id_tags_;
 };
 
 }  // namespace DEG
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index 92dff751b8a..e21a83485ad 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -2887,9 +2887,7 @@ void DepsgraphRelationBuilder::build_driver_relations(IDNode *id_node)
   }
 
   // Mapping from RNA prefix -> set of driver evaluation nodes:
-  typedef Vector<Node *> DriverGroup;
-  typedef map<string, DriverGroup> DriverGroupMap;
-  DriverGroupMap driver_groups;
+  Map<string, Vector<Node *>> driver_groups;
 
   LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) {
     if (fcu->rna_path == nullptr) {
@@ -2897,33 +2895,33 @@ void DepsgraphRelationBuilder::build_driver_relations(IDNode *id_node)
     }
     // Get the RNA path except the part after the last dot.
     char *last_dot = strrchr(fcu->rna_path, '.');
-    string rna_prefix;
+    StringRef rna_prefix;
     if (last_dot != nullptr) {
-      rna_prefix = string(fcu->rna_path, last_dot);
+      rna_prefix = StringRef(fcu->rna_path, last_dot);
     }
 
     // Insert this driver node into the group belonging to the RNA prefix.
     OperationKey driver_key(
         id_orig, NodeType::PARAMETERS, OperationCode::DRIVER, fcu->rna_path, fcu->array_index);
     Node *node_driver = get_node(driver_key);
-    driver_groups[rna_prefix].append(node_driver);
+    driver_groups.lookup_or_add_default_as(rna_prefix).append(node_driver);
   }
 
-  for (pair<string, DriverGroup> prefix_group : driver_groups) {
+  for (Span<Node *> prefix_group : driver_groups.values()) {
     // For each node in the driver group, try to connect it to another node
     // in the same group without creating any cycles.
-    int num_drivers = prefix_group.second.size();
+    int num_drivers = prefix_group.size();
     if (num_drivers < 2) {
       // A relation requires two drivers.
       continue;
     }
     for (int from_index = 0; from_index < num_drivers; ++from_index) {
-      Node *op_from = prefix_group.second[from_index];
+      Node *op_from = prefix_group[from_index];
 
       // Start by trying the next node in the group.
       for (int to_offset = 1; to_offset < num_drivers; ++to_offset) {
         int to_index = (from_index + to_offset) % num_drivers;
-        Node *op_to = prefix_group.second[to_index];
+        Node *op_to = prefix_group[to_index];
 
         // Investigate whether this relation would create a dependency cycle.
         // Example graph:
diff --git a/source/blender/depsgraph/intern/depsgraph_type.h b/source/blender/depsgraph/intern/depsgraph_type.h
index 3d386695e6c..12150320391 100644
--- a/source/blender/depsgraph/intern/depsgraph_type.h
+++ b/source/blender/depsgraph/intern/depsgraph_type.h
@@ -54,6 +54,7 @@ namespace DEG {
 
 /* Commonly used types. */
 using blender::Map;
+using blender::Optional;
 using blender::Set;
 using blender::Span;
 using blender::StringRef;
@@ -61,9 +62,7 @@ using blender::StringRefNull;
 using blender::Vector;
 using blender::VectorSet;
 using std::deque;
-using std::map;
 using std::pair;
-using std::set;
 using std::string;
 using std::unique_ptr;
 
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_modifier.cc b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_modifier.cc
index 3361c26a077..2dedba6ac5b 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_modifier.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_modifier.cc
@@ -35,15 +35,15 @@ ModifierDataBackupID::ModifierDataBackupID(ModifierData *modifier_data, Modifier
 {
 }
 
-bool ModifierDataBackupID::operator<(const ModifierDataBackupID &other) const
+bool operator==(const ModifierDataBackupID &a, const ModifierDataBackupID &b)
 {
-  if (modifier_data < other.modifier_data) {
-    return true;
-  }
-  if (modifier_data == other.modifier_data) {
-    return static_cast<int>(type) < static_cast<int>(other.type);
-  }
-  return false;
+  return a.modifier_data == b.modifier_data && a.type == b.type;
+}
+
+uint32_t ModifierDataBackupID::hash() const
+{
+  uintptr_t ptr = (uintptr_t)modifier_data;
+  return (ptr >> 4) ^ (uintptr_t)type;
 }
 
 }  // namespace DEG
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_modifier.h b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_modifier.h
index 4b3d46126f3..446e6830867 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_modifier.h
+++ b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_modifier.h
@@ -46,13 +46,15 @@ class ModifierDataBackupID {
   ModifierDataBackupID(const Depsgraph *depsgraph);
   ModifierDataBackupID(ModifierData *modifier_data, ModifierType type);
 
-  bool operator<(const ModifierDataBackupID &other) const;
+  friend bool operator==(const ModifierDataBackupID &a, const ModifierDataBackupID &b);
+
+  uint32_t hash() const;
 
   ModifierData *modifier_data;
   ModifierType type;
 };
 
 /* Storage for backed up runtime modifier data. */
-typedef map<ModifierDataBackupID, void *> ModifierRuntimeDataBackup;
+typedef Map<ModifierDataBackupID, void *> ModifierRuntimeDataBackup;
 
 }  // namespace DEG
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_object.cc b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_object.cc
index 2b172f824b6..975887ae7bf 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_object.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_runtime_backup_object.cc
@@ -75,7 +75,7 @@ void ObjectRuntimeBackup::backup_modifier_runtime_data(Object *object)
     }
     BLI_ass

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list