Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8633fc7

Browse files
committed
Avoid reading outside of collection bounds
Consider the following collection: const array = ['a', 'b', 'c'];Retrieving `array[0]` can be done relatively quickly. However, when the property doesn’t exist on the receiver, JavaScript engines must continue to look up the prototype chain until either the property is found or the chain ends. This is inherently slower than *not* doing any prototype chain lookups. Retrieving an out-of-bounds index, e.g. `array[3]`, triggers this scenario, resulting in decreased performance.This patch changes the way the `cleanData` loop is written to avoid running into the slow case unnecessarily.
1 parent692f9d4 commit8633fc7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

‎src/manipulation.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ jQuery.extend( {
285285
cleanData:function(elems){
286286
vardata,elem,type,
287287
special=jQuery.event.special,
288+
length=elems.length,
288289
i=0;
289290

290-
for(;(elem=elems[i])!==undefined;i++){
291+
for(;i<length;i++){
292+
elem=elems[i];
291293
if(acceptData(elem)){
292294
if((data=elem[dataPriv.expando])){
293295
if(data.events){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp