From 29c52b0f6caa23403fd2942aa292b84ce1278191 Mon Sep 17 00:00:00 2001 From: timmywil Date: Thu, 15 Sep 2011 16:26:35 -0400 Subject: [PATCH] Add sparse array performance improvement for inArray. Thanks rwaldron, rkatic, and jdalton --- src/core.js | 3 ++- test/unit/attributes.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index 41fa8cde6..cee1cee45 100644 --- a/src/core.js +++ b/src/core.js @@ -694,7 +694,8 @@ jQuery.extend({ i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0; for ( ; i < len; i++ ) { - if ( array[ i ] === elem ) { + // Skip accessing in sparse arrays + if ( i in array && array[ i ] === elem ) { return i; } } diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 2b68e2863..5945510de 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -156,7 +156,7 @@ test("attr(Hash)", function() { }); test("attr(String, Object)", function() { - expect(77); + expect(78); var div = jQuery("div").attr("foo", "bar"), fail = false; -- 2.39.5