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

Function decodeContextMap

js/decode.ts:471–544  ·  view source on GitHub ↗
(contextMapSize: number, contextMap: Int8Array, s: State)

Source from the content-addressed store, hash-verified

469 return readComplexHuffmanCode(alphabetSizeLimit, simpleCodeOrSkip, tableGroup, tableIdx, s);
470}
471function decodeContextMap(contextMapSize: number, contextMap: Int8Array, s: State): number {
472 let result: number;
473 if (s.halfOffset > 2030) {
474 result = readMoreInput(s);
475 if (result < 0) {
476 return result;
477 }
478 }
479 const numTrees: number = decodeVarLenUnsignedByte(s) + 1;
480 if (numTrees === 1) {
481 contextMap.fill(0, 0, contextMapSize);
482 return numTrees;
483 }
484 if (s.bitOffset >= 16) {
485 s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16);
486 s.bitOffset -= 16;
487 }
488 const useRleForZeros: number = readFewBits(s, 1);
489 let maxRunLengthPrefix = 0;
490 if (useRleForZeros !== 0) {
491 maxRunLengthPrefix = readFewBits(s, 4) + 1;
492 }
493 const alphabetSize: number = numTrees + maxRunLengthPrefix;
494 const tableSize: number = MAX_HUFFMAN_TABLE_SIZE[(alphabetSize + 31) >> 5];
495 const table = new Int32Array(tableSize + 1);
496 const tableIdx: number = table.length - 1;
497 result = readHuffmanCode(alphabetSize, alphabetSize, table, tableIdx, s);
498 if (result < 0) {
499 return result;
500 }
501 let i = 0;
502 while (i < contextMapSize) {
503 if (s.halfOffset > 2030) {
504 result = readMoreInput(s);
505 if (result < 0) {
506 return result;
507 }
508 }
509 if (s.bitOffset >= 16) {
510 s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16);
511 s.bitOffset -= 16;
512 }
513 const code: number = readSymbol(table, tableIdx, s);
514 if (code === 0) {
515 contextMap[i] = 0;
516 i++;
517 } else if (code <= maxRunLengthPrefix) {
518 if (s.bitOffset >= 16) {
519 s.accumulator32 = (s.shortBuffer[s.halfOffset++] << 16) | (s.accumulator32 >>> 16);
520 s.bitOffset -= 16;
521 }
522 let reps: number = (1 << code) + readFewBits(s, code);
523 while (reps !== 0) {
524 if (i >= contextMapSize) {
525 return makeError(s, -3);
526 }
527 contextMap[i] = 0;
528 i++;

Calls 7

readMoreInputFunction · 0.70
decodeVarLenUnsignedByteFunction · 0.70
readFewBitsFunction · 0.70
readHuffmanCodeFunction · 0.70
readSymbolFunction · 0.70
makeErrorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…