[Bf-blender-cvs] [254f164b27a] master: UI: Minor optimization to Outliner lookup for hovered element

Julian Eisel noreply at git.blender.org
Fri Jun 19 20:14:24 CEST 2020


Commit: 254f164b27a416177e3bf47bd81498a2da929e43
Author: Julian Eisel
Date:   Fri Jun 19 19:21:39 2020 +0200
Branches: master
https://developer.blender.org/rB254f164b27a416177e3bf47bd81498a2da929e43

UI: Minor optimization to Outliner lookup for hovered element

The lookup to find the hovered Outliner tree element would possibly check
children that can be skipped with a simple check.

I experimented with various ways to avoid work in this lookup. This one is
simple and reliable, which others wouldn't have been afaics. Plus, there's not
much performance to be gained here anyway.

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

M	source/blender/editors/space_outliner/outliner_utils.c

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

diff --git a/source/blender/editors/space_outliner/outliner_utils.c b/source/blender/editors/space_outliner/outliner_utils.c
index 5f19d8b8757..a120718e36b 100644
--- a/source/blender/editors/space_outliner/outliner_utils.c
+++ b/source/blender/editors/space_outliner/outliner_utils.c
@@ -84,12 +84,24 @@ TreeElement *outliner_find_item_at_y(const SpaceOutliner *soops,
         /* co_y is inside this element */
         return te_iter;
       }
-      else if (TSELEM_OPEN(te_iter->store_elem, soops)) {
-        /* co_y is lower than current element, possibly inside children */
-        TreeElement *te_sub = outliner_find_item_at_y(soops, &te_iter->subtree, view_co_y);
-        if (te_sub) {
-          return te_sub;
-        }
+
+      if (BLI_listbase_is_empty(&te_iter->subtree) || !TSELEM_OPEN(TREESTORE(te_iter), soops)) {
+        /* No need for recursion. */
+        continue;
+      }
+
+      /* If the coordinate is lower than the next element, we can continue with that one and skip
+       * recursion too. */
+      const TreeElement *te_next = te_iter->next;
+      if (te_next && (view_co_y < (te_next->ys + UI_UNIT_Y))) {
+        continue;
+      }
+
+      /* co_y is lower than current element (but not lower than the next one), possibly inside
+       * children */
+      TreeElement *te_sub = outliner_find_item_at_y(soops, &te_iter->subtree, view_co_y);
+      if (te_sub) {
+        return te_sub;
       }
     }
   }



More information about the Bf-blender-cvs mailing list