Cleanup: Reduce nesteds in node.cc #105509

Merged
Hans Goudey merged 12 commits from mod_moder/blender:cleanup_reduce_nesteds into main 2023-04-16 22:53:20 +02:00

Decompose most of the nesting in the code to make the code
more consistent along the line of program execution.
Mainly achieved through:

  • Remove redundant Else
  • Invert Condition
  • Add temporary variable to redistribute and name conditions
Decompose most of the nesting in the code to make the code more consistent along the line of program execution. Mainly achieved through: - Remove redundant Else - Invert Condition - Add temporary variable to redistribute and name conditions
Iliya Katushenock added 1 commit 2023-03-06 20:57:31 +01:00
Iliya Katushenock added 1 commit 2023-03-06 21:10:28 +01:00
Iliya Katushenock added this to the Nodes & Physics project 2023-03-06 21:10:40 +01:00
Iliya Katushenock requested review from Hans Goudey 2023-03-06 21:10:45 +01:00
Iliya Katushenock added 1 commit 2023-03-07 20:35:24 +01:00
Hans Goudey requested changes 2023-03-08 21:45:53 +01:00
Hans Goudey left a comment
Member

Thanks for the PR. To be honest though, it's quite hard to justify spend time reviewing this sort of cleanup. Compared to the amount of time review will take, the benefit is quite low. And the patch is large enough that it becomes a bit overwhelming about half-way through.

Thanks for the PR. To be honest though, it's quite hard to justify spend time reviewing this sort of cleanup. Compared to the amount of time review will take, the benefit is quite low. And the patch is large enough that it becomes a bit overwhelming about half-way through.
@ -1409,0 +1407,4 @@
return true;
}
if (!node->is_group()) {
Member

Better to keep all of the checks that are only relevant to a group node in one block:

if (node->is_group()) {
  if (group_invalid_1) {
    return false;
  }
  if (group_invalid_2) {
    return false;
  }
}

if (some other invalid check in the future) {
  return false;
}

return true;
Better to keep all of the checks that are only relevant to a group node in one block: ```cpp if (node->is_group()) { if (group_invalid_1) { return false; } if (group_invalid_2) { return false; } } if (some other invalid check in the future) { return false; } return true;
mod_moder marked this conversation as resolved
@ -2096,1 +2106,3 @@
ntree, reversed ? link->fromnode : link->tonode, callback, userdata, reversed);
/* TODO (mod_moder): This case less likely than the case below. Very less likely. Can swap.
* Need a benchmark.*/
if (ELEM(nullptr, link->tonode, link->fromnode)) {
Member

Since recently, we can assume that both tonode and fromnode will be non-null. This check is left over from the time when the currently dragged links were also stored in the node tree.

Since recently, we can assume that both `tonode` and `fromnode` will be non-null. This check is left over from the time when the currently dragged links were also stored in the node tree.
mod_moder marked this conversation as resolved
@ -2244,2 +2280,3 @@
const char *disabled_hint;
if (ntype->type == type && (!ntype->poll || ntype->poll(ntype, ntree, &disabled_hint))) {
const bool can_by_created = ntype->poll(ntype, ntree, &disabled_hint);
Member

I think the code was easier to read with ntype->poll && !ntype->poll(...) on the same line.

I think the code was easier to read with `ntype->poll && !ntype->poll(...)` on the same line.
mod_moder marked this conversation as resolved
Author
Member

I would like to complete my list of things that can be cleared in this file though (I can send it to you for approval if you want).
Reducing nesting is very useful for simplifying code. Already now it allows you to remove old unused things. Also, there is one TODO (maybe not noticed by you) that could potentially make a strong optimization (albeit not a very heavily loaded place in the code).
So this seems to have some potential for performance improvements as well.
In addition, it is also a fix for potential bugs.

I would like to complete my list of things that can be cleared in this file though (I can send it to you for approval if you want). Reducing nesting is very useful for simplifying code. Already now it allows you to remove old unused things. Also, there is one TODO (maybe not noticed by you) that could potentially make a strong optimization (albeit not a very heavily loaded place in the code). So this seems to have some potential for performance improvements as well. In addition, it is also a fix for potential bugs.
Iliya Katushenock added 2 commits 2023-03-09 20:53:15 +01:00
Iliya Katushenock requested review from Hans Goudey 2023-03-10 09:44:43 +01:00
Iliya Katushenock added 1 commit 2023-03-10 09:45:13 +01:00
Iliya Katushenock added 1 commit 2023-03-20 11:13:52 +01:00
Iliya Katushenock added 1 commit 2023-03-22 21:28:00 +01:00
Iliya Katushenock added 2 commits 2023-04-01 22:16:51 +02:00
Iliya Katushenock added 1 commit 2023-04-16 16:52:28 +02:00
Hans Goudey approved these changes 2023-04-16 21:54:52 +02:00
@ -3748,0 +3758,4 @@
if (!stype.use_link_limits_of_type) {
return sock->limit;
}
if (sock->in_out == SOCK_IN) {
Member

Personally I find this easier to read than what you've done here. It's a simple check and splitting it over multiple lines makes it seem more complex than it is.
return sock->in_out == SOCK_IN ? stype.input_link_limit : stype.output_link_limit;

Personally I find this easier to read than what you've done here. It's a simple check and splitting it over multiple lines makes it seem more complex than it is. ` return sock->in_out == SOCK_IN ? stype.input_link_limit : stype.output_link_limit;`
mod_moder marked this conversation as resolved
Iliya Katushenock added 1 commit 2023-04-16 22:40:32 +02:00
Hans Goudey merged commit 9d4949f80b into main 2023-04-16 22:53:20 +02:00
Iliya Katushenock deleted branch cleanup_reduce_nesteds 2023-04-16 22:56:29 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#105509
No description provided.