swc/bundler/tests/.cache/deno/1449d4e751812917c4513df3c9e91cb4e8ed6e20.ts
강동윤 f8aa0509ce
fix(bundler): Fix stack overflow (#2080)
swc_bundler:
 - Prevent infinite recursions. (#1963)
2021-08-15 02:37:31 +00:00

36 lines
697 B
TypeScript

// Loaded from https://deno.land/x/compress@v0.3.8/zlib/zlib/crc32.ts
export function makeTable() {
let c: number;
const table = [];
const m = 0xEDB88320;
for (let n = 0; n < 256; n++) {
c = n;
for (let k = 0; k < 8; k++) {
c = ((c & 1) ? (m ^ (c >>> 1)) : (c >>> 1));
}
table[n] = c;
}
return table;
}
// Create table on load. Just 255 signed longs. Not a problem.
const crcTable = makeTable();
export function crc32(crc: any, buf: any, len: any, pos: any) {
let t = crcTable;
let end = pos + len;
let f = 0xFF;
crc ^= -1;
for (let i = pos; i < end; i++) {
crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & f];
}
return (crc ^ (-1)); // >>> 0;
}