aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.js
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-07-16 07:32:31 +0000
committerYehuda Katz <wycats@gmail.com>2009-07-16 07:32:31 +0000
commit190812c3be99bde536d373b6b6ab65cfe053a532 (patch)
tree5754ce104b278d8b9c4af74ac87f71e92d00dc95 /src/data.js
parentd36d224cc52e70d837306d33a03f517ef72abc60 (diff)
downloadjquery-190812c3be99bde536d373b6b6ab65cfe053a532.tar.gz
jquery-190812c3be99bde536d373b6b6ab65cfe053a532.zip
Refactor jQuery.data a bit to reduce property lookups
- Also added jQuery.isEmptyObject
Diffstat (limited to 'src/data.js')
-rw-r--r--src/data.js38
1 files changed, 15 insertions, 23 deletions
diff --git a/src/data.js b/src/data.js
index 1d5fe8954..9cc76c603 100644
--- a/src/data.js
+++ b/src/data.js
@@ -8,27 +8,24 @@ jQuery.extend({
windowData :
elem;
- var id = elem[ expando ];
+ var id = elem[ expando ], cache = jQuery.cache;
// 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
// trying to access or manipulate it
- if ( name && !jQuery.cache[ id ] )
- jQuery.cache[ id ] = {};
+ if ( name && !cache[ id ] )
+ cache[ id ] = {};
- // Prevent overriding the named cache with undefined values
- if ( data !== undefined )
- jQuery.cache[ id ][ name ] = data;
+ var thisCache = cache[ id ];
- if(name === true) return jQuery.cache[ id ]
+ // Prevent overriding the named cache with undefined values
+ if ( data !== undefined ) thisCache[ name ] = data;
- // Return the named cache data, or the ID for the element
- return name ?
- jQuery.cache[ id ][ name ] :
- id;
+ if(name === true) return thisCache
+ else if(name) return thisCache[name]
+ else return id
},
removeData: function( elem, name ) {
@@ -36,21 +33,16 @@ jQuery.extend({
windowData :
elem;
- var id = elem[ expando ];
+ var id = elem[ expando ], cache = jQuery.cache, thisCache = cache[ id ];
// If we want to remove a specific section of the element's data
if ( name ) {
- if ( jQuery.cache[ id ] ) {
+ if ( thisCache ) {
// Remove the section of cache data
- delete jQuery.cache[ id ][ name ];
+ delete thisCache[ name ];
// If we've removed all the data, remove the element's cache
- name = "";
-
- for ( name in jQuery.cache[ id ] )
- break;
-
- if ( !name )
+ if( jQuery.isEmptyObject(thisCache) )
jQuery.removeData( elem );
}
@@ -67,7 +59,7 @@ jQuery.extend({
}
// Completely remove the data cache
- delete jQuery.cache[ id ];
+ delete cache[ id ];
}
},
queue: function( elem, type, data ) {