(returnFiber, currentFirstChild, newChildren, expirationTime)
| 8481 | } |
| 8482 | |
| 8483 | function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, expirationTime) { |
| 8484 | // This algorithm can't optimize by searching from boths ends since we |
| 8485 | // don't have backpointers on fibers. I'm trying to see how far we can get |
| 8486 | // with that model. If it ends up not being worth the tradeoffs, we can |
| 8487 | // add it later. |
| 8488 | |
| 8489 | // Even with a two ended optimization, we'd want to optimize for the case |
| 8490 | // where there are few changes and brute force the comparison instead of |
| 8491 | // going for the Map. It'd like to explore hitting that path first in |
| 8492 | // forward-only mode and only go for the Map once we notice that we need |
| 8493 | // lots of look ahead. This doesn't handle reversal as well as two ended |
| 8494 | // search but that's unusual. Besides, for the two ended optimization to |
| 8495 | // work on Iterables, we'd need to copy the whole set. |
| 8496 | |
| 8497 | // In this first iteration, we'll just live with hitting the bad case |
| 8498 | // (adding everything to a Map) in for every insert/move. |
| 8499 | |
| 8500 | // If you change this code, also update reconcileChildrenIterator() which |
| 8501 | // uses the same algorithm. |
| 8502 | |
| 8503 | { |
| 8504 | // First, validate keys. |
| 8505 | var knownKeys = null; |
| 8506 | for (var i = 0; i < newChildren.length; i++) { |
| 8507 | var child = newChildren[i]; |
| 8508 | knownKeys = warnOnInvalidKey(child, knownKeys); |
| 8509 | } |
| 8510 | } |
| 8511 | |
| 8512 | var resultingFirstChild = null; |
| 8513 | var previousNewFiber = null; |
| 8514 | |
| 8515 | var oldFiber = currentFirstChild; |
| 8516 | var lastPlacedIndex = 0; |
| 8517 | var newIdx = 0; |
| 8518 | var nextOldFiber = null; |
| 8519 | for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) { |
| 8520 | if (oldFiber.index > newIdx) { |
| 8521 | nextOldFiber = oldFiber; |
| 8522 | oldFiber = null; |
| 8523 | } else { |
| 8524 | nextOldFiber = oldFiber.sibling; |
| 8525 | } |
| 8526 | var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], expirationTime); |
| 8527 | if (newFiber === null) { |
| 8528 | // TODO: This breaks on empty slots like null children. That's |
| 8529 | // unfortunate because it triggers the slow path all the time. We need |
| 8530 | // a better way to communicate whether this was a miss or null, |
| 8531 | // boolean, undefined, etc. |
| 8532 | if (oldFiber === null) { |
| 8533 | oldFiber = nextOldFiber; |
| 8534 | } |
| 8535 | break; |
| 8536 | } |
| 8537 | if (shouldTrackSideEffects) { |
| 8538 | if (oldFiber && newFiber.alternate === null) { |
| 8539 | // We matched the slot, but we didn't reuse the existing fiber, so we |
| 8540 | // need to delete the existing child. |
no test coverage detected