diff options
author | jeresig <jeresig@gmail.com> | 2010-01-28 15:25:52 -0500 |
---|---|---|
committer | jeresig <jeresig@gmail.com> | 2010-01-28 15:25:52 -0500 |
commit | 98c7248518f9a2082ccf50240b5ab44bf98d7b5e (patch) | |
tree | 51295f06b30f836c8fbf28a2aaa5925e6e45e478 /src/manipulation.js | |
parent | 0252b78201f817f87d10f14c85d0f37e4c50ce22 (diff) | |
download | jquery-98c7248518f9a2082ccf50240b5ab44bf98d7b5e.tar.gz jquery-98c7248518f9a2082ccf50240b5ab44bf98d7b5e.zip |
Further optimize the empty/remove/cleanData logic.
Diffstat (limited to 'src/manipulation.js')
-rw-r--r-- | src/manipulation.js | 87 |
1 files changed, 52 insertions, 35 deletions
diff --git a/src/manipulation.js b/src/manipulation.js index 8c188c2d5..ed049de7c 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -148,6 +148,40 @@ jQuery.fn.extend({ return set; } }, + + // keepData is for internal use only--do not document + remove: function( selector, keepData ) { + for ( var i = 0, elem; (elem = this[i]) != null; i++ ) { + if ( !selector || jQuery.filter( selector, [ elem ] ).length ) { + if ( !keepData && elem.nodeType === 1 ) { + jQuery.cleanData( elem.getElementsByTagName("*") ); + jQuery.cleanData( [ elem ] ); + } + + if ( elem.parentNode ) { + elem.parentNode.removeChild( elem ); + } + } + } + + return this; + }, + + empty: function() { + for ( var i = 0, elem; (elem = this[i]) != null; i++ ) { + // Remove element nodes and prevent memory leaks + if ( elem.nodeType === 1 ) { + jQuery.cleanData( elem.getElementsByTagName("*") ); + } + + // Remove any remaining nodes + while ( elem.firstChild ) { + elem.removeChild( elem.firstChild ); + } + } + + return this; + }, clone: function( events ) { // Do the clone @@ -391,38 +425,6 @@ jQuery.each({ }; }); -jQuery.each({ - // keepData is for internal use only--do not document - remove: function( selector, keepData ) { - if ( !selector || jQuery.filter( selector, [ this ] ).length ) { - if ( !keepData && this.nodeType === 1 ) { - jQuery.cleanData( this.getElementsByTagName("*") ); - jQuery.cleanData( [ this ] ); - } - - if ( this.parentNode ) { - this.parentNode.removeChild( this ); - } - } - }, - - empty: function() { - // Remove element nodes and prevent memory leaks - if ( this.nodeType === 1 ) { - jQuery.cleanData( this.getElementsByTagName("*") ); - } - - // Remove any remaining nodes - while ( this.firstChild ) { - this.removeChild( this.firstChild ); - } - } -}, function( name, fn ) { - jQuery.fn[ name ] = function() { - return this.each( fn, arguments ); - }; -}); - jQuery.extend({ clean: function( elems, context, fragment, scripts ) { context = context || document; @@ -519,9 +521,24 @@ jQuery.extend({ }, cleanData: function( elems ) { - for ( var i = 0, elem, id; (elem = elems[i]) != null; i++ ) { - jQuery.event.remove( elem ); - jQuery.removeData( elem ); + var data, id, cache = jQuery.cache; + + for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) { + id = elem[ jQuery.expando ]; + + if ( id ) { + data = cache[ id ]; + + if ( data.events ) { + for ( var event in data.events ) { + removeEvent( elem, event, data.handle ); + } + } + + removeExpando( elem ); + + delete cache[ id ]; + } } } }); |