Skip to content

Commit 157ab2f

Browse files
committed
Implement fast path for init_hydrate binary search
1 parent a15f39c commit 157ab2f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/runtime/internal/dom.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ function init_hydrate(target: NodeEx) {
8282
// Find the largest subsequence length such that it ends in a value less than our current value
8383

8484
// upper_bound returns first greater value, so we subtract one
85-
const seqLen = upper_bound(1, longest + 1, idx => children[m[idx]].claim_order, current) - 1;
85+
// with fast path for when we are on the current longest subsequence
86+
const seqLen = ((longest > 0 && children[m[longest]].claim_order <= current) ? longest + 1 : upper_bound(1, longest, idx => children[m[idx]].claim_order, current)) - 1;
8687

8788
p[i] = m[seqLen] + 1;
8889

0 commit comments

Comments
 (0)