File tree Expand file tree Collapse file tree
src/SharpCompress/Compressors/Rar Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using System ;
2+ using SharpCompress . Crypto ;
23
34namespace SharpCompress . Compressors . Rar ;
45
56internal static class RarCRC
67{
7- private static readonly uint [ ] crcTab ;
8+ // Reuse Crc32Stream's cached slice-by-16 table (same polynomial) instead of a separate
9+ // byte-at-a-time table, so bulk CRC checks during Rar extraction get the same throughput
10+ // as Zip/GZip/7Zip/LZip CRC32 validation instead of a much slower one-byte-per-iteration loop.
11+ private static readonly uint [ ] crcTab = Crc32Stream . InitializeTable (
12+ Crc32Stream . DEFAULT_POLYNOMIAL
13+ ) ;
814
915 public static uint CheckCrc ( uint startCrc , byte b ) =>
1016 ( crcTab [ ( ( int ) startCrc ^ b ) & 0xff ] ^ ( startCrc >> 8 ) ) ;
1117
1218 public static uint CheckCrc ( uint startCrc , ReadOnlySpan < byte > data , int offset , int count )
1319 {
1420 var size = Math . Min ( data . Length - offset , count ) ;
15-
16- for ( var i = 0 ; i < size ; i ++ )
17- {
18- startCrc = ( crcTab [ ( ( int ) startCrc ^ data [ offset + i ] ) & 0xff ] ^ ( startCrc >> 8 ) ) ;
19- }
20- return ( startCrc ) ;
21- }
22-
23- static RarCRC ( )
24- {
25- {
26- crcTab = new uint [ 256 ] ;
27- for ( uint i = 0 ; i < 256 ; i ++ )
28- {
29- var c = i ;
30- for ( var j = 0 ; j < 8 ; j ++ )
31- {
32- if ( ( c & 1 ) != 0 )
33- {
34- c >>= 1 ;
35- c ^= 0xEDB88320 ;
36- }
37- else
38- {
39- c >>= 1 ;
40- }
41- }
42- crcTab [ i ] = c ;
43- }
44- }
21+ return Crc32Stream . CalculateCrc ( crcTab , startCrc , data . Slice ( offset , size ) ) ;
4522 }
4623}
You can’t perform that action at this time.
0 commit comments