Skip to content

Commit e29d9bc

Browse files
yoshielpil
authored andcommitted
skip computing the node index if it's not needed
1 parent 8e2517f commit e29d9bc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/dict.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,11 @@ function doPut(transient, node, key, value, hash, shift) {
418418
}
419419

420420
const bit = hashbit(hash, shift);
421-
const nodeidx = data.length - 1 - index(nodemap, bit);
422421

423422
// 2. Child Node
424423
// We have to check first if there is already a child node we have to traverse to.
425424
if ((nodemap & bit) !== 0) {
425+
const nodeidx = data.length - 1 - index(nodemap, bit);
426426
const child = data[nodeidx];
427427
data[nodeidx] = doPut(transient, child, key, value, hash, shift + bits);
428428
return node;
@@ -473,6 +473,8 @@ function doPut(transient, node, key, value, hash, shift) {
473473
// 2 extra elements, but missing the one we haven't inserted yet, so we have
474474
// to correct for both of these with (1-2) = -1
475475

476+
const nodeidx = data.length - 1 - index(nodemap, bit);
477+
476478
data.splice(dataidx, 2);
477479
data.splice(nodeidx - 1, 0, child);
478480

0 commit comments

Comments
 (0)