From d0fec7c6fb0b53d18b5219870c5cc9950731f7b3 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 20 Nov 2018 13:24:43 +0100 Subject: [PATCH] Fix `NameOrNumberTree.get` to actually perform a binary search to find the requested key The intent of the code, based on existing comments, is to perform a binary search. However, because of what appears to be a typo in the code responsible for computing the current search index, this code is always checking *every* entry (albeit only at the "final" node) starting from the last one. --- src/core/obj.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/obj.js b/src/core/obj.js index 019fe5bf6..7a875a216 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -1686,7 +1686,7 @@ class NameOrNumberTree { while (l <= r) { // Check only even indices (0, 2, 4, ...) because the // odd indices contain the actual data. - const m = (l + r) & ~1; + const tmp = (l + r) >> 1, m = tmp + (tmp & 1); const currentKey = xref.fetchIfRef(entries[m]); if (key < currentKey) { r = m - 2;