Add sparse array performance improvement for inArray. Thanks rwaldron, rkatic, and jdalton

This commit is contained in:
timmywil 2011-09-15 16:26:35 -04:00
parent 76a84fba94
commit 29c52b0f6c
2 changed files with 3 additions and 2 deletions

View File

@ -694,7 +694,8 @@ jQuery.extend({
i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0; i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
for ( ; i < len; i++ ) { for ( ; i < len; i++ ) {
if ( array[ i ] === elem ) { // Skip accessing in sparse arrays
if ( i in array && array[ i ] === elem ) {
return i; return i;
} }
} }

View File

@ -156,7 +156,7 @@ test("attr(Hash)", function() {
}); });
test("attr(String, Object)", function() { test("attr(String, Object)", function() {
expect(77); expect(78);
var div = jQuery("div").attr("foo", "bar"), var div = jQuery("div").attr("foo", "bar"),
fail = false; fail = false;