Hey all,

Looking at the new source code for 1.3, I was wondering why jQuery
doesn't take advantage of the native replaceChild method in the W3C
core. Currently, jQuery implements replaceWith using append and
remove, but since replaceChild is well supported[1] across browsers,
it seems like a safe place to optimize performance, since it reduces
two in-place DOM operations with one.

So I replaced this on line 487 in 1.3:

replaceWith: function( value ) {
  return this.after( value ).remove();
},

with this:

replaceWith: function() {
  return this.domManip(arguments, false, function(elem){
    this.parentNode.replaceChild( elem, this );
  });
},

and put together a before[2] and after[3] page.

On OS 10.5.6, Firefox 3.0.5 went from an average of 1239ms to 935ms,
and Safari 3.2.1 went from an average of 421ms to 331ms.

What do you guys think?

Jed Schmidt

[1] http://www.quirksmode.org/dom/w3c_core.html
[2] http://s3.amazonaws.com/replacewith/before.html
[3] http://s3.amazonaws.com/replacewith/after.html
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to