Skip to content

Commit

Permalink
Use a shorter expression for the typed array size if any.
Browse files Browse the repository at this point in the history
  • Loading branch information
lifthrasiir committed Sep 10, 2021
1 parent 48ace3d commit eb74630
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,17 @@ export class Packer {
return 'θ';
};

let contextSize;
{
let v = numModels, shift = contextBits;
while (v % 2 == 0) {
v >>= 1;
++shift;
}
contextSize = `${v}<<${shift}`;
// we can also make use of θ, but that wouldn't work in the argument position
}

// 0. first line
// ι: compressed data, where lowest 6 bits are used and higher bits are chosen to avoid escape sequences.
// this should be isolated from other code for the best DEFLATE result.
Expand Down Expand Up @@ -987,8 +998,8 @@ export class Packer {
const secondLineInit = [
[`θ`, `1<<${precision + 1}`],
[`ω`, `${JSON.stringify(Array(numModels).fill(0))}`],
[`π`, `new Uint${predictionBits}Array(${numModels}<<${contextBits}).fill(1<<${precision - 1})`],
[`κ`, `new Uint${countBits}Array(${numModels}<<${contextBits})`],
[`π`, `new Uint${predictionBits}Array(${contextSize}).fill(1<<${precision - 1})`],
[`κ`, `new Uint${countBits}Array(${contextSize})`],
];
if (!options.allowFreeVars) {
// see step 2 for the description
Expand Down

0 comments on commit eb74630

Please sign in to comment.