mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
avoid creating a new data cache if we don't need one. Also, short-circuit the case where $.data is used to get the cache id
This commit is contained in:
parent
19cd84cf32
commit
c4f144eeff
21
src/data.js
21
src/data.js
@ -1,4 +1,5 @@
|
|||||||
var expando = "jQuery" + now(), uuid = 0, windowData = {};
|
var expando = "jQuery" + now(), uuid = 0, windowData = {};
|
||||||
|
var emptyObject = {};
|
||||||
|
|
||||||
jQuery.extend({
|
jQuery.extend({
|
||||||
cache: {},
|
cache: {},
|
||||||
@ -10,24 +11,28 @@ jQuery.extend({
|
|||||||
windowData :
|
windowData :
|
||||||
elem;
|
elem;
|
||||||
|
|
||||||
var id = elem[ expando ], cache = jQuery.cache;
|
var id = elem[ expando ], cache = jQuery.cache, thisCache;
|
||||||
|
|
||||||
// Compute a unique ID for the element
|
// Compute a unique ID for the element
|
||||||
if(!id) id = elem[ expando ] = ++uuid;
|
if(!id) id = elem[ expando ] = ++uuid;
|
||||||
|
|
||||||
// Only generate the data cache if we're
|
// Handle the case where there's no name immediately
|
||||||
// trying to access or manipulate it
|
if ( !name ) { return id; }
|
||||||
if ( name && !cache[ id ] )
|
|
||||||
cache[ id ] = {};
|
|
||||||
|
|
||||||
var thisCache = cache[ id ];
|
// Avoid generating a new cache unless none exists and we
|
||||||
|
// want to manipulate it.
|
||||||
|
if( cache[ id ] )
|
||||||
|
thisCache = cache[ id ];
|
||||||
|
else if( typeof data === "undefined" )
|
||||||
|
thisCache = emptyObject;
|
||||||
|
else
|
||||||
|
thisCache = cache[ id ] = {};
|
||||||
|
|
||||||
// Prevent overriding the named cache with undefined values
|
// Prevent overriding the named cache with undefined values
|
||||||
if ( data !== undefined ) thisCache[ name ] = data;
|
if ( data !== undefined ) thisCache[ name ] = data;
|
||||||
|
|
||||||
if(name === true) return thisCache;
|
if(name === true) return thisCache;
|
||||||
else if(name) return thisCache[name];
|
else return thisCache[name];
|
||||||
else return id;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
removeData: function( elem, name ) {
|
removeData: function( elem, name ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user