facebook/react — pull request #879 by syranide (2014-01-13 21:59:09+00:00)
Title: Remove unnecessary tests from insertChildAt and inline it instead

```
if (childNodes[index] === childNode) {
return;
}
if (childNode.parentNode === parentNode) {
parentNode.removeChild(childNode);
}
```

A `childNode` to be inserted/moved cannot find itself already in the DOM. It has already been detached by `processUpdates` as it was added to `updatedChildren` as part of the setup. *If* it had been added twice to the list of updates `processUpdates` would throw an error as it would try to detach it twice.

---

```
if (index >= childNodes.length) {
parentNode.appendChild(childNode);
} else {
parentNode.insertBefore(childNode, childNodes[index]);
}
```

`appendChild(node)` behaves identically to `insertBefore(node, null)`, however arrays return `undefined` for an undefined index. IE8 (and possibly others) do not like this, so by adding `|| null` we're all set!

---

```
function insertChildAt(parentNode, childNode, index) {
parentNode.insertBefore(childNode, parentNode.childNodes[index] || null);
}
```

Now that there's nothing left of the function, we can just go ahead and inline it as it's basically nothing more than an alias for `insertBefore` now.

---

```
raw gz Compared to last run
= = build/JSXTransformer.js
-759 -220 build/react-with-addons.js
-52 -48 build/react-with-addons.min.js
-759 -230 build/react.js
-52 -47 build/react.min.js
```