var expando = "jQuery" + now(), uuid = 0, windowData = {};\r
+var emptyObject = {};\r
\r
jQuery.extend({\r
cache: {},\r
windowData :\r
elem;\r
\r
- var id = elem[ expando ], cache = jQuery.cache;\r
+ var id = elem[ expando ], cache = jQuery.cache, thisCache;\r
\r
// Compute a unique ID for the element\r
if(!id) id = elem[ expando ] = ++uuid;\r
\r
- // Only generate the data cache if we're\r
- // trying to access or manipulate it\r
- if ( name && !cache[ id ] )\r
- cache[ id ] = {};\r
-\r
- var thisCache = cache[ id ];\r
+ // Handle the case where there's no name immediately\r
+ if ( !name ) { return id; }\r
\r
+ // Avoid generating a new cache unless none exists and we\r
+ // want to manipulate it.\r
+ if( cache[ id ] )\r
+ thisCache = cache[ id ];\r
+ else if( typeof data === "undefined" )\r
+ thisCache = emptyObject;\r
+ else\r
+ thisCache = cache[ id ] = {};\r
+ \r
// Prevent overriding the named cache with undefined values\r
if ( data !== undefined ) thisCache[ name ] = data;\r
\r
if(name === true) return thisCache;\r
- else if(name) return thisCache[name];\r
- else return id;\r
+ else return thisCache[name];\r
},\r
\r
removeData: function( elem, name ) {\r