Skip to content

Commit

Permalink
Add sparse array performance improvement for inArray. Thanks rwaldron…
Browse files Browse the repository at this point in the history
…, rkatic, and jdalton
  • Loading branch information
timmywil committed Sep 19, 2011
1 parent 76a84fb commit 29c52b0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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;
} }
} }
Expand Down
2 changes: 1 addition & 1 deletion test/unit/attributes.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 29c52b0

Please sign in to comment.