Merge pull request #879 from syranide/inlinechild

Remove unnecessary tests from insertChildAt and inline it instead
This commit is contained in:
Paul O’Shannessy 2014-04-24 15:02:14 -07:00
commit a0dc45e652

View File

@ -42,20 +42,14 @@ var textContentAccessor = getTextContentAccessor();
* @internal * @internal
*/ */
function insertChildAt(parentNode, childNode, index) { function insertChildAt(parentNode, childNode, index) {
var childNodes = parentNode.childNodes; // By exploiting arrays returning `undefined` for an undefined index, we can
if (childNodes[index] === childNode) { // rely exclusively on `insertBefore(node, null)` instead of also using
return; // `appendChild(node)`. However, using `undefined` is not allowed by all
} // browsers so we must replace it with `null`.
// If `childNode` is already a child of `parentNode`, remove it so that parentNode.insertBefore(
// computing `childNodes[index]` takes into account the removal. childNode,
if (childNode.parentNode === parentNode) { parentNode.childNodes[index] || null
parentNode.removeChild(childNode); );
}
if (index >= childNodes.length) {
parentNode.appendChild(childNode);
} else {
parentNode.insertBefore(childNode, childNodes[index]);
}
} }
var updateTextContent; var updateTextContent;