From a16bb391db52c9ce367111439e8d9482e3a65f2d Mon Sep 17 00:00:00 2001 From: Altan Birler Date: Sun, 27 Jun 2021 07:13:41 +0200 Subject: [PATCH] Implement fast path for `init_hydrate` binary search --- src/runtime/internal/dom.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index c325689c3a..d1b5264791 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -82,8 +82,9 @@ function init_hydrate(target: NodeEx) { // Find the largest subsequence length such that it ends in a value less than our current value // upper_bound returns first greater value, so we subtract one - const seqLen = upper_bound(1, longest + 1, idx => children[m[idx]].claim_order, current) - 1; - + // with fast path for when we are on the current longest subsequence + const seqLen = ((longest > 0 && children[m[longest]].claim_order <= current) ? longest + 1 : upper_bound(1, longest, idx => children[m[idx]].claim_order, current)) - 1; + p[i] = m[seqLen] + 1; const newLen = seqLen + 1;