You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by jm...@apache.org on 2007/10/03 01:19:58 UTC
svn commit: r581457 - /incubator/xap/trunk/codebase/src/google/dom.js
Author: jmargaris
Date: Tue Oct 2 18:19:58 2007
New Revision: 581457
URL: http://svn.apache.org/viewvc?rev=581457&view=rev
Log:
RemoveChild more efficient
Modified:
incubator/xap/trunk/codebase/src/google/dom.js
Modified: incubator/xap/trunk/codebase/src/google/dom.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/google/dom.js?rev=581457&r1=581456&r2=581457&view=diff
==============================================================================
--- incubator/xap/trunk/codebase/src/google/dom.js (original)
+++ incubator/xap/trunk/codebase/src/google/dom.js Tue Oct 2 18:19:58 2007
@@ -219,27 +219,26 @@
//IMPORTANT why does this declare a whole new array instead of just
//using splice and the like?
XNode.prototype.removeChild = function(node) {
- var newChildren = [];
- for (var i = 0; i < this.childNodes.length; ++i) {
- var c = this.childNodes[i];
- if (c != node) {
- newChildren.push(c);
- } else {
- if (c.previousSibling) {
- c.previousSibling.nextSibling = c.nextSibling;
- }
- if (c.nextSibling) {
- c.nextSibling.previousSibling = c.previousSibling;
- }
- if (this.firstChild == c) {
- this.firstChild = c.nextSibling;
- }
- if (this.lastChild == c) {
- this.lastChild = c.previousSibling;
- }
- }
- }
- this.childNodes = newChildren;
+ var c;
+ for (var i = this.childNodes.length-1; i>=0; i--){
+ c = this.childNodes[i];
+ if (c===node){
+ this.childNodes.splice(i,1);
+ if (c.previousSibling) {
+ c.previousSibling.nextSibling = c.nextSibling;
+ }
+ if (c.nextSibling) {
+ c.nextSibling.previousSibling = c.previousSibling;
+ }
+ if (this.firstChild == c) {
+ this.firstChild = c.nextSibling;
+ }
+ if (this.lastChild == c) {
+ this.lastChild = c.previousSibling;
+ }
+ break;
+ }
+ }
}