MCPcopy
hub / github.com/google/brotli / readHuffmanCodeLengths

Function readHuffmanCodeLengths

js/decode.ts:290–357  ·  view source on GitHub ↗
(codeLengthCodeLengths: Int32Array, numSymbols: number, codeLengths: Int32Array, s: State)

Source from the content-addressed store, hash-verified

288 }
289}
290function readHuffmanCodeLengths(codeLengthCodeLengths: Int32Array, numSymbols: number, codeLengths: Int32Array, s: State): number {
291 let symbol = 0;
292 let prevCodeLen = 8;
293 let repeat = 0;
294 let repeatCodeLen = 0;
295 let space = 32768;
296 const table = new Int32Array(33);
297 const tableIdx: number = table.length - 1;
298 buildHuffmanTable(table, tableIdx, 5, codeLengthCodeLengths, 18);
299 while (symbol < numSymbols && space > 0) {
300 if (s.halfOffset > 2030) {
301 const result: number = readMoreInput(s);
302 if (result < 0) {
303 return result;
304 }
305 }
306 if (s.bitOffset >= 16) {
307 s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16);
308 s.bitOffset -= 16;
309 }
310 const p: number = (s.accumulator32 >>> s.bitOffset) & 31;
311 s.bitOffset += table[p] >> 16;
312 const codeLen: number = table[p] & 0xFFFF;
313 if (codeLen < 16) {
314 repeat = 0;
315 codeLengths[symbol++] = codeLen;
316 if (codeLen !== 0) {
317 prevCodeLen = codeLen;
318 space -= 32768 >> codeLen;
319 }
320 } else {
321 const extraBits: number = codeLen - 14;
322 let newLen = 0;
323 if (codeLen === 16) {
324 newLen = prevCodeLen;
325 }
326 if (repeatCodeLen !== newLen) {
327 repeat = 0;
328 repeatCodeLen = newLen;
329 }
330 const oldRepeat: number = repeat;
331 if (repeat > 0) {
332 repeat -= 2;
333 repeat = repeat << extraBits;
334 }
335 if (s.bitOffset >= 16) {
336 s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16);
337 s.bitOffset -= 16;
338 }
339 repeat += readFewBits(s, extraBits) + 3;
340 const repeatDelta: number = repeat - oldRepeat;
341 if (symbol + repeatDelta > numSymbols) {
342 return makeError(s, -2);
343 }
344 for (let i = 0; i < repeatDelta; ++i) {
345 codeLengths[symbol++] = repeatCodeLen;
346 }
347 if (repeatCodeLen !== 0) {

Callers 1

readComplexHuffmanCodeFunction · 0.70

Calls 4

buildHuffmanTableFunction · 0.70
readMoreInputFunction · 0.70
readFewBitsFunction · 0.70
makeErrorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…