Skip to content

Commit

Permalink
Merge pull request facebook#879 from syranide/inlinechild
Browse files Browse the repository at this point in the history
Remove unnecessary tests from insertChildAt and inline it instead
  • Loading branch information
zpao committed Apr 24, 2014
2 parents cc292c1 + 9ee1d92 commit a0dc45e
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/browser/ui/dom/DOMChildrenOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,14 @@ var textContentAccessor = getTextContentAccessor();
* @internal
*/
function insertChildAt(parentNode, childNode, index) {
var childNodes = parentNode.childNodes;
if (childNodes[index] === childNode) {
return;
}
// If `childNode` is already a child of `parentNode`, remove it so that
// computing `childNodes[index]` takes into account the removal.
if (childNode.parentNode === parentNode) {
parentNode.removeChild(childNode);
}
if (index >= childNodes.length) {
parentNode.appendChild(childNode);
} else {
parentNode.insertBefore(childNode, childNodes[index]);
}
// By exploiting arrays returning `undefined` for an undefined index, we can
// rely exclusively on `insertBefore(node, null)` instead of also using
// `appendChild(node)`. However, using `undefined` is not allowed by all
// browsers so we must replace it with `null`.
parentNode.insertBefore(
childNode,
parentNode.childNodes[index] || null
);
}

var updateTextContent;
Expand Down

0 comments on commit a0dc45e

Please sign in to comment.