@@ -113,7 +113,7 @@ public static void decompress(BZipContext bzip2Context) {
113
113
else
114
114
curr --;
115
115
} while (true );
116
- bzip2Context .aByteArrayArray822 [t ][i ] = (byte ) curr ;
116
+ bzip2Context .codeLengths [t ][i ] = (byte ) curr ;
117
117
}
118
118
119
119
}
@@ -122,14 +122,14 @@ public static void decompress(BZipContext bzip2Context) {
122
122
byte minLen = 32 ;
123
123
int maxLen = 0 ;
124
124
for (int i = 0 ; i < alphaSize ; i ++) {
125
- if (bzip2Context .aByteArrayArray822 [t ][i ] > maxLen )
126
- maxLen = bzip2Context .aByteArrayArray822 [t ][i ];
127
- if (bzip2Context .aByteArrayArray822 [t ][i ] < minLen )
128
- minLen = bzip2Context .aByteArrayArray822 [t ][i ];
125
+ if (bzip2Context .codeLengths [t ][i ] > maxLen )
126
+ maxLen = bzip2Context .codeLengths [t ][i ];
127
+ if (bzip2Context .codeLengths [t ][i ] < minLen )
128
+ minLen = bzip2Context .codeLengths [t ][i ];
129
129
}
130
130
131
- method294 (bzip2Context .limit [t ], bzip2Context .base [t ], bzip2Context .perm [t ],
132
- bzip2Context .aByteArrayArray822 [t ], minLen , maxLen , alphaSize );
131
+ createHuffmanDecodingTables (bzip2Context .limit [t ], bzip2Context .base [t ], bzip2Context .perm [t ],
132
+ bzip2Context .codeLengths [t ], minLen , maxLen , alphaSize );
133
133
bzip2Context .minLens [t ] = minLen ;
134
134
}
135
135
@@ -299,7 +299,7 @@ else if (nextSym == 1)
299
299
bzip2Context .tPos >>= 8 ;
300
300
bzip2Context .nBlockUsed ++;
301
301
bzip2Context .nBlock = nblock ;
302
- method291 (bzip2Context );
302
+ finalDecompressionStep (bzip2Context );
303
303
flag19 = bzip2Context .nBlockUsed == bzip2Context .nBlock + 1 && bzip2Context .stateOutLen == 0 ;
304
304
}
305
305
}
@@ -335,141 +335,152 @@ public static void makeMaps(BZipContext context) {
335
335
}
336
336
}
337
337
338
- public static void method291 (BZipContext arg0 ) {
339
- byte i = arg0 .stateOutCh ;
340
- int i_0_ = arg0 .stateOutLen ;
341
- int i_1_ = arg0 .nBlockUsed ;
342
- int i_2_ = arg0 .anInt811 ;
343
- int [] is = BZipContext .tt ;
344
- int i_3_ = arg0 .tPos ;
345
- byte [] is_4_ = arg0 .aByteArray837 ;
346
- int i_5_ = arg0 .anInt825 ;
347
- int i_6_ = arg0 .anInt823 ;
348
- int i_7_ = i_6_ ;
349
- int i_8_ = arg0 .nBlock + 1 ;
350
- while_10_ :
338
+ public static void finalDecompressionStep (BZipContext bz ) {
339
+ byte currentByte = bz .stateOutCh ;
340
+ int remainingBytes = bz .stateOutLen ;
341
+ int blockUsed = bz .nBlockUsed ;
342
+ int lastByte = bz .anInt811 ;
343
+ int [] tt = BZipContext .tt ;
344
+ int tPos = bz .tPos ;
345
+ byte [] output = bz .aByteArray837 ;
346
+ int outputPos = bz .anInt825 ;
347
+ int outputRemaining = bz .anInt823 ;
348
+ int outputStart = outputRemaining ;
349
+ int blockEnd = bz .nBlock + 1 ;
350
+ outerLoop :
351
351
for (; ; ) {
352
- if (i_0_ > 0 ) {
352
+ if (remainingBytes > 0 ) {
353
353
for (; ; ) {
354
- if (i_6_ == 0 )
355
- break while_10_ ;
356
- if (i_0_ == 1 )
354
+ if (outputRemaining == 0 )
355
+ break outerLoop ;
356
+ if (remainingBytes == 1 )
357
357
break ;
358
- is_4_ [ i_5_ ] = i ;
359
- i_0_ --;
360
- i_5_ ++;
361
- i_6_ --;
358
+ output [ outputPos ] = currentByte ;
359
+ remainingBytes --;
360
+ outputPos ++;
361
+ outputRemaining --;
362
362
}
363
- if (i_6_ == 0 ) {
364
- i_0_ = 1 ;
363
+ if (outputRemaining == 0 ) {
364
+ remainingBytes = 1 ;
365
365
break ;
366
366
}
367
- is_4_ [ i_5_ ] = i ;
368
- i_5_ ++;
369
- i_6_ --;
367
+ output [ outputPos ] = currentByte ;
368
+ outputPos ++;
369
+ outputRemaining --;
370
370
}
371
371
boolean bool = true ;
372
372
while (bool ) {
373
373
bool = false ;
374
- if (i_1_ == i_8_ ) {
375
- i_0_ = 0 ;
376
- break while_10_ ;
374
+ if (blockUsed == blockEnd ) {
375
+ remainingBytes = 0 ;
376
+ break outerLoop ;
377
377
}
378
- i = (byte ) i_2_ ;
379
- i_3_ = is [ i_3_ ];
380
- int i_9_ = (byte ) (i_3_ & 0xff );
381
- i_3_ >>= 8 ;
382
- i_1_ ++;
383
- if (i_9_ != i_2_ ) {
384
- i_2_ = i_9_ ;
385
- if (i_6_ == 0 ) {
386
- i_0_ = 1 ;
387
- break while_10_ ;
378
+ currentByte = (byte ) lastByte ;
379
+ tPos = tt [ tPos ];
380
+ int nextByte = (byte ) (tPos & 0xff );
381
+ tPos >>= 8 ;
382
+ blockUsed ++;
383
+ if (nextByte != lastByte ) {
384
+ lastByte = nextByte ;
385
+ if (outputRemaining == 0 ) {
386
+ remainingBytes = 1 ;
387
+ break outerLoop ;
388
388
}
389
- is_4_ [ i_5_ ] = i ;
390
- i_5_ ++;
391
- i_6_ --;
389
+ output [ outputPos ] = currentByte ;
390
+ outputPos ++;
391
+ outputRemaining --;
392
392
bool = true ;
393
- } else if (i_1_ == i_8_ ) {
394
- if (i_6_ == 0 ) {
395
- i_0_ = 1 ;
396
- break while_10_ ;
393
+ } else if (blockUsed == blockEnd ) {
394
+ if (outputRemaining == 0 ) {
395
+ remainingBytes = 1 ;
396
+ break outerLoop ;
397
397
}
398
- is_4_ [ i_5_ ] = i ;
399
- i_5_ ++;
400
- i_6_ --;
398
+ output [ outputPos ] = currentByte ;
399
+ outputPos ++;
400
+ outputRemaining --;
401
401
bool = true ;
402
402
}
403
403
}
404
- i_0_ = 2 ;
405
- i_3_ = is [ i_3_ ];
406
- int i_10_ = (byte ) (i_3_ & 0xff );
407
- i_3_ >>= 8 ;
408
- if (++i_1_ != i_8_ ) {
409
- if (i_10_ == i_2_ ) {
410
- i_0_ = 3 ;
411
- i_3_ = is [ i_3_ ];
412
- i_10_ = (byte ) (i_3_ & 0xff );
413
- i_3_ >>= 8 ;
414
- if (++i_1_ != i_8_ ) {
415
- if (i_10_ == i_2_ ) {
416
- i_3_ = is [ i_3_ ];
417
- i_10_ = (byte ) (i_3_ & 0xff );
418
- i_3_ >>= 8 ;
419
- i_1_ ++;
420
- i_0_ = (i_10_ & 0xff ) + 4 ;
421
- i_3_ = is [ i_3_ ];
422
- i_2_ = (byte ) (i_3_ & 0xff );
423
- i_3_ >>= 8 ;
424
- i_1_ ++;
404
+ remainingBytes = 2 ;
405
+ tPos = tt [ tPos ];
406
+ int nextByte = (byte ) (tPos & 0xff );
407
+ tPos >>= 8 ;
408
+ if (++blockUsed != blockEnd ) {
409
+ if (nextByte == lastByte ) {
410
+ remainingBytes = 3 ;
411
+ tPos = tt [ tPos ];
412
+ nextByte = (byte ) (tPos & 0xff );
413
+ tPos >>= 8 ;
414
+ if (++blockUsed != blockEnd ) {
415
+ if (nextByte == lastByte ) {
416
+ tPos = tt [ tPos ];
417
+ nextByte = (byte ) (tPos & 0xff );
418
+ tPos >>= 8 ;
419
+ blockUsed ++;
420
+ remainingBytes = (nextByte & 0xff ) + 4 ;
421
+ tPos = tt [ tPos ];
422
+ lastByte = (byte ) (tPos & 0xff );
423
+ tPos >>= 8 ;
424
+ blockUsed ++;
425
425
} else
426
- i_2_ = i_10_ ;
426
+ lastByte = nextByte ;
427
427
}
428
428
} else
429
- i_2_ = i_10_ ;
429
+ lastByte = nextByte ;
430
430
}
431
431
}
432
- arg0 .anInt846 += i_7_ - i_6_ ;
433
- arg0 .stateOutCh = i ;
434
- arg0 .stateOutLen = i_0_ ;
435
- arg0 .nBlockUsed = i_1_ ;
436
- arg0 .anInt811 = i_2_ ;
437
- BZipContext .tt = is ;
438
- arg0 .tPos = i_3_ ;
439
- arg0 .aByteArray837 = is_4_ ;
440
- arg0 .anInt825 = i_5_ ;
441
- arg0 .anInt823 = i_6_ ;
432
+ bz .anInt846 += outputStart - outputRemaining ;
433
+ bz .stateOutCh = currentByte ;
434
+ bz .stateOutLen = remainingBytes ;
435
+ bz .nBlockUsed = blockUsed ;
436
+ bz .anInt811 = lastByte ;
437
+ BZipContext .tt = tt ;
438
+ bz .tPos = tPos ;
439
+ bz .aByteArray837 = output ;
440
+ bz .anInt825 = outputPos ;
441
+ bz .anInt823 = outputRemaining ;
442
442
}
443
443
444
444
public static byte getBit (BZipContext context ) {
445
445
return (byte ) getBits (1 , context );
446
446
}
447
447
448
- public static void method294 (int [] arg0 , int [] arg1 , int [] arg2 , byte [] arg3 , int arg4 , int arg5 , int arg6 ) {
448
+ private static void createHuffmanDecodingTables (int [] limit , int [] base , int [] perm , byte [] codeLengths , int minLen , int maxLen , int alphabetSize ) {
449
449
int i = 0 ;
450
- for (int i_84_ = arg4 ; i_84_ <= arg5 ; i_84_ ++) {
451
- for (int i_85_ = 0 ; i_85_ < arg6 ; i_85_ ++) {
452
- if (arg3 [i_85_ ] == i_84_ ) {
453
- arg2 [i ] = i_85_ ;
450
+
451
+ // Populate the mapping from canonical code index to output symbol
452
+ for (int len = minLen ; len <= maxLen ; len ++) {
453
+ for (int symIndex = 0 ; symIndex < alphabetSize ; symIndex ++) {
454
+ if (codeLengths [symIndex ] == len ) {
455
+ perm [i ] = symIndex ;
454
456
i ++;
455
457
}
456
458
}
457
459
}
458
- for (int i_86_ = 0 ; i_86_ < 23 ; i_86_ ++)
459
- arg1 [i_86_ ] = 0 ;
460
- for (int i_87_ = 0 ; i_87_ < arg6 ; i_87_ ++)
461
- arg1 [arg3 [i_87_ ] + 1 ]++;
462
- for (int i_88_ = 1 ; i_88_ < 23 ; i_88_ ++)
463
- arg1 [i_88_ ] += arg1 [i_88_ - 1 ];
464
- for (int i_89_ = 0 ; i_89_ < 23 ; i_89_ ++)
465
- arg0 [i_89_ ] = 0 ;
466
- int i_90_ = 0 ;
467
- for (int i_91_ = arg4 ; i_91_ <= arg5 ; i_91_ ++) {
468
- i_90_ += arg1 [i_91_ + 1 ] - arg1 [i_91_ ];
469
- arg0 [i_91_ ] = i_90_ - 1 ;
470
- i_90_ <<= 1 ;
460
+
461
+ // reset base arrays
462
+ for (int index = 0 ; index < 23 ; index ++)
463
+ base [index ] = 0 ;
464
+ for (int index = 0 ; index < alphabetSize ; index ++)
465
+ base [codeLengths [index ] + 1 ]++;
466
+ for (int index = 1 ; index < 23 ; index ++)
467
+ base [index ] += base [index - 1 ];
468
+
469
+ // reset limit array
470
+ for (int index = 0 ; index < 23 ; index ++)
471
+ limit [index ] = 0 ;
472
+
473
+ // Calculate the first and last Huffman code for each code length (codes at a given
474
+ // length are sequential in value)
475
+ int code = 0 ;
476
+ for (int len = minLen ; len <= maxLen ; len ++) {
477
+ code += base [len + 1 ] - base [len ];
478
+ limit [len ] = code - 1 ;
479
+ code <<= 1 ;
471
480
}
472
- for (int i_92_ = arg4 + 1 ; i_92_ <= arg5 ; i_92_ ++)
473
- arg1 [i_92_ ] = (arg0 [i_92_ - 1 ] + 1 << 1 ) - arg1 [i_92_ ];
481
+
482
+ // Update base array with appropriate values for decoding
483
+ for (int len = minLen + 1 ; len <= maxLen ; len ++)
484
+ base [len ] = (limit [len - 1 ] + 1 << 1 ) - base [len ];
474
485
}
475
486
}
0 commit comments