From b7f90368ee771a7e57def6f261f3d267b5f3f210 Mon Sep 17 00:00:00 2001 From: Caridy Date: Mon, 11 Dec 2017 15:49:20 -0500 Subject: [PATCH] fixes issue #348: perf optimization during diffing algo to avoid calling addVNodes and removeVNodes when there is nothing to do. --- src/snabbdom.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/snabbdom.ts b/src/snabbdom.ts index ed7b524..9b6b44d 100644 --- a/src/snabbdom.ts +++ b/src/snabbdom.ts @@ -240,11 +240,13 @@ export function init(modules: Array>, domApi?: DOMAPI) { } } } - if (oldStartIdx > oldEndIdx) { - before = newCh[newEndIdx+1] == null ? null : newCh[newEndIdx+1].elm; - addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx, insertedVnodeQueue); - } else if (newStartIdx > newEndIdx) { - removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx); + if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) { + if (oldStartIdx > oldEndIdx) { + before = newCh[newEndIdx+1] == null ? null : newCh[newEndIdx+1].elm; + addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx, insertedVnodeQueue); + } else { + removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx); + } } }