Skip to content

Commit

Permalink
Sync fflate huffman tree with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Nov 26, 2023
1 parent 61624a6 commit 9ce3f8f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/wasm-util/src/fflate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ const hMap = ((cd: Uint8Array, mb: number, r: 0 | 1) => {
// u16 "map": index -> # of codes with bit length = index
const l = new u16(mb);
// length of cd must be 288 (total # of codes)
for (; i < s; ++i) ++l[cd[i] - 1];
for (; i < s; ++i) {
if (cd[i]) ++l[cd[i] - 1];
}
// u16 "map": index -> minimum code for bit length = index
const le = new u16(mb);
for (i = 0; i < mb; ++i) {
for (i = 1; i < mb; ++i) {
le[i] = (le[i - 1] + l[i - 1]) << 1;
}
let co: Uint16Array;
Expand All @@ -116,13 +118,17 @@ const hMap = ((cd: Uint8Array, mb: number, r: 0 | 1) => {
// m is end value
for (const m = v | ((1 << r) - 1); v <= m; ++v) {
// every 16 bit value starting with the code yields the same result
co[rev[v] >>> rvb] = sv;
co[rev[v] >> rvb] = sv;
}
}
}
} else {
co = new u16(s);
for (i = 0; i < s; ++i) co[i] = rev[le[cd[i] - 1]++] >>> (15 - cd[i]);
for (i = 0; i < s; ++i) {
if (cd[i]) {
co[i] = rev[le[cd[i] - 1]++] >> (15 - cd[i]);
}
}
}
return co;
});
Expand Down

0 comments on commit 9ce3f8f

Please sign in to comment.