Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Micro optimize Node contains
Browse files Browse the repository at this point in the history
  • Loading branch information
arv committed Feb 27, 2014
1 parent 7578669 commit b9217f8
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/wrappers/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@
return clone;
}

function contains(self, child) {
// TODO(arv): Optimize using ownerDocument etc.
for (var node = child; node; node = node.parentNode) {
if (node === self)
return true;
}
return false;
}

var OriginalNode = window.Node;

/**
Expand Down Expand Up @@ -640,18 +649,7 @@
},

contains: function(child) {
if (!child)
return false;

child = wrapIfNeeded(child);

// TODO(arv): Optimize using ownerDocument etc.
if (child === this)
return true;
var parentNode = child.parentNode;
if (!parentNode)
return false;
return this.contains(parentNode);
return contains(this, wrapIfNeeded(child));
},

compareDocumentPosition: function(otherNode) {
Expand Down

0 comments on commit b9217f8

Please sign in to comment.