Added TreeOutline.removeChildAtIndex and TreeElement.removeChildAtIndex
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Jul 2008 02:47:33 +0000 (02:47 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Jul 2008 02:47:33 +0000 (02:47 +0000)
        for efficiency of callers that know the index of the child. This
        will be used in an upcoming change.

        Reviewed by Adam Roben.

        * page/inspector/treeoutline.js:
        (TreeOutline._removeChildAtIndex): Renamed from _removeChild
        and modified to take an index.
        (TreeOutline._removeChild): Call _removeChildAtIndex with the
        child index found using indexOf.
        (TreeOutline.prototype.removeChildAtIndex): Added. Calls
        TreeOutline._removeChildAtIndex.
        (TreeElement.prototype.removeChildAtIndex): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@35313 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/page/inspector/treeoutline.js

index 4207b95..ad0623c 100644 (file)
@@ -1,5 +1,22 @@
 2008-07-21  Timothy Hatcher  <timothy@apple.com>
 
 2008-07-21  Timothy Hatcher  <timothy@apple.com>
 
+        Added TreeOutline.removeChildAtIndex and TreeElement.removeChildAtIndex
+        for efficiency of callers that know the index of the child. This
+        will be used in an upcoming change.
+
+        Reviewed by Adam Roben.
+
+        * page/inspector/treeoutline.js:
+        (TreeOutline._removeChildAtIndex): Renamed from _removeChild
+        and modified to take an index.
+        (TreeOutline._removeChild): Call _removeChildAtIndex with the
+        child index found using indexOf.
+        (TreeOutline.prototype.removeChildAtIndex): Added. Calls
+        TreeOutline._removeChildAtIndex.
+        (TreeElement.prototype.removeChildAtIndex): Ditto.
+
+2008-07-21  Timothy Hatcher  <timothy@apple.com>
+
         Fixes a regression where TreeOutline.findTreeElement would
         return the parent TreeElement of the representedObject instead
         of the TreeElement for the representedObject. Regressed with the
         Fixes a regression where TreeOutline.findTreeElement would
         return the parent TreeElement of the representedObject instead
         of the TreeElement for the representedObject. Regressed with the
index 5df0f7d..163e357 100644 (file)
@@ -133,17 +133,13 @@ TreeOutline._insertChild = function(child, index)
     child._attach();
 }
 
     child._attach();
 }
 
-TreeOutline._removeChild = function(child)
+TreeOutline._removeChildAtIndex = function(childIndex)
 {
 {
-    if (!child)
-        throw("child can't be undefined or null");
+    if (childIndex < 0 || childIndex >= this.children.length)
+        throw("childIndex out of range");
 
 
-    for (var i = 0; i < this.children.length; ++i) {
-        if (this.children[i] === child) {
-            this.children.splice(i, 1);
-            break;
-        }
-    }
+    var child = this.children[childIndex];
+    this.children.splice(childIndex, 1);
 
     child.deselect();
 
 
     child.deselect();
 
@@ -161,6 +157,18 @@ TreeOutline._removeChild = function(child)
     child.previousSibling = null;
 }
 
     child.previousSibling = null;
 }
 
+TreeOutline._removeChild = function(child)
+{
+    if (!child)
+        throw("child can't be undefined or null");
+
+    var childIndex = this.children.indexOf(child);
+    if (childIndex === -1)
+        throw("child not found in this node's children");
+
+    TreeOutline._removeChildAtIndex.call(this, childIndex);
+}
+
 TreeOutline._removeChildren = function()
 {
     for (var i = 0; i < this.children.length; ++i) {
 TreeOutline._removeChildren = function()
 {
     for (var i = 0; i < this.children.length; ++i) {
@@ -395,6 +403,7 @@ TreeOutline.prototype.reveal = function()
 TreeOutline.prototype.appendChild = TreeOutline._appendChild;
 TreeOutline.prototype.insertChild = TreeOutline._insertChild;
 TreeOutline.prototype.removeChild = TreeOutline._removeChild;
 TreeOutline.prototype.appendChild = TreeOutline._appendChild;
 TreeOutline.prototype.insertChild = TreeOutline._insertChild;
 TreeOutline.prototype.removeChild = TreeOutline._removeChild;
+TreeOutline.prototype.removeChildAtIndex = TreeOutline._removeChildAtIndex;
 TreeOutline.prototype.removeChildren = TreeOutline._removeChildren;
 TreeOutline.prototype.removeChildrenRecursive = TreeOutline._removeChildrenRecursive;
 
 TreeOutline.prototype.removeChildren = TreeOutline._removeChildren;
 TreeOutline.prototype.removeChildrenRecursive = TreeOutline._removeChildrenRecursive;
 
@@ -491,6 +500,7 @@ TreeElement.prototype = {
 TreeElement.prototype.appendChild = TreeOutline._appendChild;
 TreeElement.prototype.insertChild = TreeOutline._insertChild;
 TreeElement.prototype.removeChild = TreeOutline._removeChild;
 TreeElement.prototype.appendChild = TreeOutline._appendChild;
 TreeElement.prototype.insertChild = TreeOutline._insertChild;
 TreeElement.prototype.removeChild = TreeOutline._removeChild;
+TreeElement.prototype.removeChildAtIndex = TreeOutline._removeChildAtIndex;
 TreeElement.prototype.removeChildren = TreeOutline._removeChildren;
 TreeElement.prototype.removeChildrenRecursive = TreeOutline._removeChildrenRecursive;
 
 TreeElement.prototype.removeChildren = TreeOutline._removeChildren;
 TreeElement.prototype.removeChildrenRecursive = TreeOutline._removeChildrenRecursive;