chiark / gitweb /
documentation: properly calculate child offset for 11bit result counts.
authorVladimír Vondruš <mosra@centrum.cz>
Sat, 8 Jan 2022 20:51:24 +0000 (21:51 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Sat, 8 Jan 2022 22:17:00 +0000 (23:17 +0100)
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

index 4b65e9aba5d135364d3d479bb016b5e87e40c2d0..2ab06bd91c725d6089a519fce3ef3dc3ed02d0b6 100644 (file)
@@ -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);