Skip to content

Commit

Permalink
Skip around inserting a fragment when possible (insert the node direc…
Browse files Browse the repository at this point in the history
…tly).
  • Loading branch information
jeresig committed Jan 28, 2010
1 parent b8076a9 commit 388a00f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/manipulation.js
Expand Up @@ -296,7 +296,7 @@ jQuery.fn.extend({
},

domManip: function( args, table, callback ) {
var results, first, value = args[0], scripts = [];
var results, first, value = args[0], scripts = [], fragment;

// We can't cloneNode fragments that contain checked, in WebKit
if ( !jQuery.support.checkClone && arguments.length === 3 && typeof value === "string" && rchecked.test( value ) ) {
Expand All @@ -320,8 +320,14 @@ jQuery.fn.extend({
} else {
results = buildFragment( args, this, scripts );
}

first = results.fragment.firstChild;

fragment = results.fragment;

if ( fragment.childNodes.length === 1 ) {
first = fragment = fragment.firstChild;
} else {
first = fragment.firstChild;
}

if ( first ) {
table = table && jQuery.nodeName( first, "tr" );
Expand All @@ -331,14 +337,14 @@ jQuery.fn.extend({
table ?
root(this[i], first) :
this[i],
results.cacheable || this.length > 1 || i > 0 ?
results.fragment.cloneNode(true) :
results.fragment
i > 0 || results.cacheable || this.length > 1 ?
fragment.cloneNode(true) :
fragment
);
}
}

if ( scripts ) {
if ( scripts.length ) {
jQuery.each( scripts, evalScript );
}
}
Expand Down

0 comments on commit 388a00f

Please sign in to comment.