Skip to content

Commit 4b7e1c9

Browse files
committed
Brought back the compareDocumentPosition code. While it is redundant in Firefox it's much faster than using indexOf.
1 parent 8d9aa01 commit 4b7e1c9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/selector.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,15 @@ try {
684684

685685
var sortOrder;
686686

687-
if ( Array.prototype.indexOf ) {
687+
if ( document.documentElement.compareDocumentPosition ) {
688+
sortOrder = function( a, b ) {
689+
var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1;
690+
if ( ret === 0 ) {
691+
hasDuplicate = true;
692+
}
693+
return ret;
694+
};
695+
} else if ( Array.prototype.indexOf ) {
688696
var indexOf = Array.prototype.indexOf,
689697
allSort = document.getElementsByTagName("*");
690698

@@ -695,7 +703,7 @@ if ( Array.prototype.indexOf ) {
695703
}
696704
return ret;
697705
};
698-
} else if ( document.documentElement.sourceIndex === 1 ) {
706+
} else if ( "sourceIndex" in document.documentElement ) {
699707
sortOrder = function( a, b ) {
700708
var ret = a.sourceIndex - b.sourceIndex;
701709
if ( ret === 0 ) {

test/unit/selector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module("selector");
22

33
test("element", function() {
4-
expect(17);
4+
expect(18);
55
reset();
66

77
ok( jQuery("*").size() >= 30, "Select all" );
@@ -25,7 +25,7 @@ test("element", function() {
2525
ok( jQuery("#lengthtest input").length, '<input name="length"> cannot be found under IE, see #945' );
2626

2727
// Check for unique-ness and sort order
28-
//isSet( jQuery("*"), jQuery("*, *"), "Check for duplicates: *, *" );
28+
isSet( jQuery("*"), jQuery("*, *"), "Check for duplicates: *, *" );
2929
isSet( jQuery("p"), jQuery("p, div p"), "Check for duplicates: p, div p" );
3030

3131
t( "Checking sort order", "h2, h1", ["header", "banner", "userAgent"] );

0 commit comments

Comments
 (0)