[Bf-blender-cvs] [3d72b941963] master: Depsgraph: Use array instead of set for node factory

Sergey Sharybin noreply at git.blender.org
Fri Dec 15 17:48:57 CET 2017


Commit: 3d72b941963da38f35ad8f9bc7eefc7ba77c6cd4
Author: Sergey Sharybin
Date:   Fri Dec 15 17:42:07 2017 +0100
Branches: master
https://developer.blender.org/rB3d72b941963da38f35ad8f9bc7eefc7ba77c6cd4

Depsgraph: Use array instead of set for node factory

Avoids extra time spent on hashing and such.

Old comment is kind of weird, because types we can totally make a sequent
integer values.

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

M	source/blender/depsgraph/intern/depsgraph_type_defines.cc

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

diff --git a/source/blender/depsgraph/intern/depsgraph_type_defines.cc b/source/blender/depsgraph/intern/depsgraph_type_defines.cc
index e5bdaf79366..b81914b461b 100644
--- a/source/blender/depsgraph/intern/depsgraph_type_defines.cc
+++ b/source/blender/depsgraph/intern/depsgraph_type_defines.cc
@@ -51,14 +51,7 @@ namespace DEG {
 
 /* Global type registry */
 
-/**
- * \note For now, this is a hashtable not array, since the core node types
- * currently do not have contiguous ID values. Using a hash here gives us
- * more flexibility, albeit using more memory and also sacrificing a little
- * speed. Later on, when things stabilise we may turn this back to an array
- * since there are only just a few node types that an array would cope fine...
- */
-static GHash *_depsnode_typeinfo_registry = NULL;
+static DepsNodeFactory *depsnode_typeinfo_registry[NUM_DEG_NODE_TYPES] = {NULL};
 
 /* Registration ------------------------------------------- */
 
@@ -66,9 +59,7 @@ static GHash *_depsnode_typeinfo_registry = NULL;
 void deg_register_node_typeinfo(DepsNodeFactory *factory)
 {
 	BLI_assert(factory != NULL);
-	BLI_ghash_insert(_depsnode_typeinfo_registry,
-	                 SET_INT_IN_POINTER(factory->type()),
-	                 factory);
+	depsnode_typeinfo_registry[factory->type()] = factory;
 }
 
 /* Getters ------------------------------------------------- */
@@ -77,8 +68,7 @@ void deg_register_node_typeinfo(DepsNodeFactory *factory)
 DepsNodeFactory *deg_get_node_factory(const eDepsNode_Type type)
 {
 	/* look up type - at worst, it doesn't exist in table yet, and we fail */
-	return (DepsNodeFactory *)BLI_ghash_lookup(_depsnode_typeinfo_registry,
-	                                           SET_INT_IN_POINTER(type));
+	return depsnode_typeinfo_registry[type];
 }
 
 /* Get typeinfo for provided node */
@@ -169,9 +159,6 @@ const char *DepsOperationStringifier::operator[](eDepsOperation_Code opcode)
 /* Register all node types */
 void DEG_register_node_types(void)
 {
-	/* initialise registry */
-	DEG::_depsnode_typeinfo_registry = BLI_ghash_int_new("Depsgraph Node Type Registry");
-
 	/* register node types */
 	DEG::deg_register_base_depsnodes();
 	DEG::deg_register_component_depsnodes();
@@ -181,5 +168,4 @@ void DEG_register_node_types(void)
 /* Free registry on exit */
 void DEG_free_node_types(void)
 {
-	BLI_ghash_free(DEG::_depsnode_typeinfo_registry, NULL, NULL);
 }



More information about the Bf-blender-cvs mailing list