mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Optimize cleanData: allow direct access to data_priv for cleanup
This commit is contained in:
parent
5e8a5f4adc
commit
c1b8edfcc9
@ -185,7 +185,9 @@ Data.prototype = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
discard: function( owner ) {
|
discard: function( owner ) {
|
||||||
delete this.cache[ this.key( owner ) ];
|
if ( owner[ this.expando ] ) {
|
||||||
|
delete this.cache[ owner[ this.expando ] ];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -433,35 +433,35 @@ jQuery.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
cleanData: function( elems ) {
|
cleanData: function( elems ) {
|
||||||
var data, elem, type,
|
var data, elem, events, type, key, j,
|
||||||
l = elems.length,
|
special = jQuery.event.special,
|
||||||
i = 0,
|
i = 0;
|
||||||
special = jQuery.event.special;
|
|
||||||
|
|
||||||
for ( ; i < l; i++ ) {
|
for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
|
||||||
elem = elems[ i ];
|
if ( Data.accepts( elem ) ) {
|
||||||
|
key = elem[ data_priv.expando ];
|
||||||
|
|
||||||
if ( jQuery.acceptData( elem ) ) {
|
if ( key && (data = data_priv.cache[ key ]) ) {
|
||||||
|
events = Object.keys( data.events || {} );
|
||||||
|
if ( events.length ) {
|
||||||
|
for ( j = 0; (type = events[j]) !== undefined; j++ ) {
|
||||||
|
if ( special[ type ] ) {
|
||||||
|
jQuery.event.remove( elem, type );
|
||||||
|
|
||||||
data = data_priv.access( elem );
|
// This is a shortcut to avoid jQuery.event.remove's overhead
|
||||||
|
} else {
|
||||||
if ( data ) {
|
jQuery.removeEvent( elem, type, data.handle );
|
||||||
for ( type in data.events ) {
|
}
|
||||||
if ( special[ type ] ) {
|
|
||||||
jQuery.event.remove( elem, type );
|
|
||||||
|
|
||||||
// This is a shortcut to avoid jQuery.event.remove's overhead
|
|
||||||
} else {
|
|
||||||
jQuery.removeEvent( elem, type, data.handle );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( data_priv.cache[ key ] ) {
|
||||||
|
// Discard any remaining `private` data
|
||||||
|
delete data_priv.cache[ key ];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Discard any remaining `private` and `user` data
|
// Discard any remaining `user` data
|
||||||
// One day we'll replace the dual arrays with a WeakMap and this won't be an issue.
|
delete data_user.cache[ elem[ data_user.expando ] ];
|
||||||
// (Splices the data objects out of the internal cache arrays)
|
|
||||||
data_user.discard( elem );
|
|
||||||
data_priv.discard( elem );
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user