From 26cc1aeb5bb2e7e08f15b0649bdc4423b1b20761 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 8 Jan 2022 21:51:24 +0100 Subject: [PATCH] documentation: properly calculate child offset for 11bit result counts. Instead of fetching the exact same value twice and then forgetting to patch it in one case, let's just reuse the patched value. Hmmmm, this was a bug! And no tests caught it! Though, it was rather unlikely to be hit in practice as the 100+th result would be cut away, thus not even giving the user a hint to type futther. --- documentation/search.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/documentation/search.js b/documentation/search.js index 4b65e9ab..2ab06bd9 100644 --- a/documentation/search.js +++ b/documentation/search.js @@ -256,7 +256,6 @@ var Search = { for(; foundPrefix != searchString.length; ++foundPrefix) { /* Calculate offset and count of children */ let offset = this.searchStack[this.searchStack.length - 1]; - let relChildOffset = 2 + this.trie.getUint8(offset)*2; /* Calculate child count. If there's a lot of results, the count "leaks over" to the child count storage. */ @@ -268,7 +267,7 @@ var Search = { } /* Go through all children and find the next offset */ - let childOffset = offset + relChildOffset; + let childOffset = offset + 2 + resultCount*2; let found = false; for(let j = 0; j != childCount; ++j) { if(String.fromCharCode(this.trie.getUint8(childOffset + j*4 + 3)) != searchString[foundPrefix]) @@ -339,9 +338,7 @@ var Search = { } /* Dig deeper */ - /* TODO: hmmm. this is helluvalot duplicated code. hmm. */ - let relChildOffset = 2 + this.trie.getUint8(offset)*2; - let childOffset = offset + relChildOffset; + let childOffset = offset + 2 + resultCount*2; for(let j = 0; j != childCount; ++j) { let offsetBarrier = this.trie.getUint32(childOffset + j*4, true); -- 2.30.2