git.asbjorn.biz
/
jquery.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
19cd84c
)
avoid creating a new data cache if we don't need one. Also, short-circuit the case...
author
Yehuda Katz
<wycats@gmail.com>
Tue, 15 Sep 2009 07:59:53 +0000
(07:59 +0000)
committer
Yehuda Katz
<wycats@gmail.com>
Tue, 15 Sep 2009 07:59:53 +0000
(07:59 +0000)
src/data.js
patch
|
blob
|
history
diff --git
a/src/data.js
b/src/data.js
index
4b557de
..
c18e73c
100644
(file)
--- a/
src/data.js
+++ b/
src/data.js
@@
-1,4
+1,5
@@
var expando = "jQuery" + now(), uuid = 0, windowData = {};
\r
var expando = "jQuery" + now(), uuid = 0, windowData = {};
\r
+var emptyObject = {};
\r
\r
jQuery.extend({
\r
cache: {},
\r
\r
jQuery.extend({
\r
cache: {},
\r
@@
-10,24
+11,28
@@
jQuery.extend({
windowData :
\r
elem;
\r
\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
\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
\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
// 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
},
\r
\r
removeData: function( elem, name ) {
\r