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 (from parent 1:
48164ee
)
Overhauled the .remove() and .empty() methods to be much more efficient. Fixes bug...
author
John Resig
<jeresig@gmail.com>
Mon, 23 Feb 2009 16:32:45 +0000
(16:32 +0000)
committer
John Resig
<jeresig@gmail.com>
Mon, 23 Feb 2009 16:32:45 +0000
(16:32 +0000)
src/core.js
patch
|
blob
|
history
diff --git
a/src/core.js
b/src/core.js
index
65960e2
..
a9e7536
100644
(file)
--- a/
src/core.js
+++ b/
src/core.js
@@
-1225,23
+1225,27
@@
jQuery.each({
remove: function( selector ) {
if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
remove: function( selector ) {
if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
- // Prevent memory leaks
- jQuery( "*", this ).add([this]).each(function(){
- jQuery.event.remove(this);
- jQuery.removeData(this);
- });
- if (this.parentNode)
+ if ( this.nodeType === 1 ) {
+ cleanData( this.getElementsByTagName("*") );
+ cleanData( [this] );
+ }
+
+ if ( this.parentNode ) {
this.parentNode.removeChild( this );
this.parentNode.removeChild( this );
+ }
}
},
empty: function() {
// Remove element nodes and prevent memory leaks
}
},
empty: function() {
// Remove element nodes and prevent memory leaks
- jQuery(this).children().remove();
+ if ( this.nodeType === 1 ) {
+ cleanData( this.getElementsByTagName("*") );
+ }
// Remove any remaining nodes
// Remove any remaining nodes
- while ( this.firstChild )
+ while ( this.firstChild ) {
this.removeChild( this.firstChild );
this.removeChild( this.firstChild );
+ }
}
}, function(name, fn){
jQuery.fn[ name ] = function(){
}
}, function(name, fn){
jQuery.fn[ name ] = function(){
@@
-1249,6
+1253,15
@@
jQuery.each({
};
});
};
});
+function cleanData( elems ) {
+ for ( var i = 0, l = elems.length; i < l; i++ ) {
+ var id = elems[i][expando];
+ if ( id ) {
+ delete jQuery.cache[ id ];
+ }
+ }
+}
+
// Helper function used by the dimensions and offset modules
function num(elem, prop) {
return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;
// Helper function used by the dimensions and offset modules
function num(elem, prop) {
return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0;