Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2020-08-21 12:21:16 +0300
committerSybren A. Stüvel <sybren@blender.org>2020-08-21 13:18:48 +0300
commite7767ba6be99a85349975b8da37b8cb8b9a3d6a9 (patch)
tree5a9ccda4dff54d828f7465e3ccde0764a19653e5 /source/blender/blenkernel/intern/scene.c
parent7aeaf5da0eaf2310f9b984f953f9a3a2ea02883c (diff)
Cleanup: Reduce nesting of `scene_get_depsgraph_p()`
Reduce nesting by flipping conditions and returning early. It's now much clearer that it's actually a linear function (rather than a nested one). No functional changes.
Diffstat (limited to 'source/blender/blenkernel/intern/scene.c')
-rw-r--r--source/blender/blenkernel/intern/scene.c51
1 files changed, 29 insertions, 22 deletions
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 9edd56c984f..552076f87ca 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -2266,31 +2266,38 @@ static Depsgraph **scene_get_depsgraph_p(Main *bmain,
*/
DepsgraphKey key;
key.view_layer = view_layer;
+
Depsgraph **depsgraph_ptr;
- if (allocate_ghash_entry) {
- DepsgraphKey **key_ptr;
- if (!BLI_ghash_ensure_p_ex(
- scene->depsgraph_hash, &key, (void ***)&key_ptr, (void ***)&depsgraph_ptr)) {
- *key_ptr = MEM_mallocN(sizeof(DepsgraphKey), __func__);
- **key_ptr = key;
- if (allocate_depsgraph) {
- *depsgraph_ptr = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_VIEWPORT);
- /* TODO(sergey): Would be cool to avoid string format print,
- * but is a bit tricky because we can't know in advance whether
- * we will ever enable debug messages for this depsgraph.
- */
- char name[1024];
- BLI_snprintf(name, sizeof(name), "%s :: %s", scene->id.name, view_layer->name);
- DEG_debug_name_set(*depsgraph_ptr, name);
- }
- else {
- *depsgraph_ptr = NULL;
- }
- }
- }
- else {
+ if (!allocate_ghash_entry) {
depsgraph_ptr = (Depsgraph **)BLI_ghash_lookup_p(scene->depsgraph_hash, &key);
+ return depsgraph_ptr;
}
+
+ DepsgraphKey **key_ptr;
+ if (BLI_ghash_ensure_p_ex(
+ scene->depsgraph_hash, &key, (void ***)&key_ptr, (void ***)&depsgraph_ptr)) {
+ /* Depsgraph was found in the ghash. */
+ return depsgraph_ptr;
+ }
+
+ if (!allocate_depsgraph) {
+ /* Not found and not allowed to allocate. */
+ *depsgraph_ptr = NULL;
+ return depsgraph_ptr;
+ }
+
+ *key_ptr = MEM_mallocN(sizeof(DepsgraphKey), __func__);
+ **key_ptr = key;
+
+ *depsgraph_ptr = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_VIEWPORT);
+ /* TODO(sergey): Would be cool to avoid string format print,
+ * but is a bit tricky because we can't know in advance whether
+ * we will ever enable debug messages for this depsgraph.
+ */
+ char name[1024];
+ BLI_snprintf(name, sizeof(name), "%s :: %s", scene->id.name, view_layer->name);
+ DEG_debug_name_set(*depsgraph_ptr, name);
+
return depsgraph_ptr;
}