Title: [136706] trunk/Source/WebCore
Revision
136706
Author
[email protected]
Date
2012-12-05 09:45:56 -0800 (Wed, 05 Dec 2012)

Log Message

Web Inspector: more robust treeoutline.findTreeElement
https://bugs.webkit.org/show_bug.cgi?id=103911

Patch by John J. Barton <[email protected]> on 2012-12-05
Reviewed by Vsevolod Vlasov.

Non-recursive algorithm to populate the treeoutline given an DOMNode
as representedObject. Walk up the parents from the desired object
until we find one that is currently represented in the treeoutline
cache. Then walk down, putting children in the cache until we get
to the desired object again.
With Pavel Feldeman <[email protected]>

No new tests, refactoring, no new function

       * inspector/front-end/treeoutline.js:
(TreeOutline.prototype.findTreeElement):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (136705 => 136706)


--- trunk/Source/WebCore/ChangeLog	2012-12-05 17:44:40 UTC (rev 136705)
+++ trunk/Source/WebCore/ChangeLog	2012-12-05 17:45:56 UTC (rev 136706)
@@ -1,3 +1,22 @@
+2012-12-05  John J. Barton  <[email protected]>
+
+        Web Inspector: more robust treeoutline.findTreeElement
+        https://bugs.webkit.org/show_bug.cgi?id=103911
+
+        Reviewed by Vsevolod Vlasov.
+
+        Non-recursive algorithm to populate the treeoutline given an DOMNode
+        as representedObject. Walk up the parents from the desired object
+        until we find one that is currently represented in the treeoutline 
+        cache. Then walk down, putting children in the cache until we get 
+        to the desired object again. 
+        With Pavel Feldeman <[email protected]>
+
+        No new tests, refactoring, no new function
+
+       * inspector/front-end/treeoutline.js:
+        (TreeOutline.prototype.findTreeElement):
+
 2012-12-05  Alexander Shalamov  <[email protected]>
 
         [EFL][GTK] List value response headers are not handled in RespourceResponse (libsoup specific)

Modified: trunk/Source/WebCore/inspector/front-end/treeoutline.js (136705 => 136706)


--- trunk/Source/WebCore/inspector/front-end/treeoutline.js	2012-12-05 17:44:40 UTC (rev 136705)
+++ trunk/Source/WebCore/inspector/front-end/treeoutline.js	2012-12-05 17:45:56 UTC (rev 136706)
@@ -245,45 +245,24 @@
     if (cachedElement)
         return cachedElement;
 
-    // The representedObject isn't known, so we start at the top of the tree and work down to find the first
-    // tree element that represents representedObject or one of its ancestors.
-    var item;
-    var found = false;
-    for (var i = 0; i < this.children.length; ++i) {
-        item = this.children[i];
-        if (item.representedObject === representedObject || isAncestor(item.representedObject, representedObject)) {
-            found = true;
+    // Walk up the parent pointers from the desired representedObject 
+    var ancestors = [];
+    for (var currentObject = getParent(representedObject); currentObject;  currentObject = getParent(currentObject)) {
+        ancestors.push(currentObject);
+        if (this.getCachedTreeElement(currentObject))  // stop climbing as soon as we hit
             break;
-        }
     }
-
-    if (!found)
+        
+    if (!currentObject)
         return null;
 
-    // Make sure the item that we found is connected to the root of the tree.
-    // Build up a list of representedObject's ancestors that aren't already in our tree.
-    var ancestors = [];
-    var currentObject = representedObject;
-    while (currentObject) {
-        ancestors.unshift(currentObject);
-        if (currentObject === item.representedObject)
-            break;
-        currentObject = getParent(currentObject);
+    // Walk down to populate each ancestor's children, to fill in the tree and the cache.
+    for (var i = ancestors.length - 1; i >= 0; --i) {
+        var treeElement = this.getCachedTreeElement(ancestors[i]);
+        if (treeElement)
+            treeElement.onpopulate();  // fill the cache with the children of treeElement
     }
 
-    // For each of those ancestors we populate them to fill in the tree.
-    for (var i = 0; i < ancestors.length; ++i) {
-        // Make sure we don't call findTreeElement with the same representedObject
-        // again, to prevent infinite recursion.
-        if (ancestors[i] === representedObject)
-            continue;
-        // FIXME: we could do something faster than findTreeElement since we will know the next
-        // ancestor exists in the tree.
-        item = this.findTreeElement(ancestors[i], isAncestor, getParent);
-        if (item)
-            item.onpopulate();
-    }
-
     return this.getCachedTreeElement(representedObject);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to