aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-10-09 21:33:02 -0700
committerwycats <wycats@gmail.com>2010-10-09 21:33:02 -0700
commit0ca35de311ff4d1dac5c9dc4de05a32a1754cd7a (patch)
tree7319a8a94e5601c052ea79be91d3d923f2ee0188 /src
parentcbf9d874e52212d0289deae747066eccfebde770 (diff)
downloadjquery-0ca35de311ff4d1dac5c9dc4de05a32a1754cd7a.tar.gz
jquery-0ca35de311ff4d1dac5c9dc4de05a32a1754cd7a.zip
Should improve performance of closest considerably. Benchmark proof in speed/closest.html
Diffstat (limited to 'src')
-rw-r--r--src/traversing.js30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/traversing.js b/src/traversing.js
index f57819d86..1633e2e16 100644
--- a/src/traversing.js
+++ b/src/traversing.js
@@ -8,6 +8,8 @@ var runtil = /Until$/,
isSimple = /^.[^:#\[\.,]*$/,
slice = Array.prototype.slice;
+var POS = jQuery.expr.match.POS;
+
jQuery.fn.extend({
find: function( selector ) {
// Handle "> div" child selectors and pass them to .children()
@@ -95,21 +97,27 @@ jQuery.fn.extend({
return ret;
}
- var pos = jQuery.expr.match.POS.test( selectors ) ?
+ var pos = POS.test( selectors ) ?
jQuery( selectors, context || this.context ) : null;
- ret = jQuery.map(this.get(),function( cur,i ) {
- while ( cur && cur.ownerDocument && cur !== context ) {
- if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selectors) ) {
- return cur;
- }
+ var ret = [];
- cur = cur.parentNode;
- }
+ for ( var i=0,j=this.length; i<j; i++ ) {
+ var cur = this[i];
+
+ while ( cur ) {
+ if ( pos ? pos.index(cur) > -1 : jQuery.find.matches(selectors, [cur]).length ) {
+ ret.push( cur );
+ break;
+ } else {
+ cur = cur.parentNode;
+ if ( !cur.ownerDocument || cur === context ) {
+ break;
+ }
+ }
+ }
+ }
- return null;
- });
-
ret = ret.length > 1 ? jQuery.unique(ret) : ret;
return this.pushStack( ret, "closest", selectors );