File tree 1 file changed +23
-2
lines changed
src/ICSharpCode.SharpZipLib/BZip2
1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ public class BZip2InputStream : Stream
19
19
private const int NO_RAND_PART_B_STATE = 6 ;
20
20
private const int NO_RAND_PART_C_STATE = 7 ;
21
21
22
+ #if NETSTANDARD2_1
23
+ private static readonly int VectorSize = System . Numerics . Vector < byte > . Count ;
24
+ #endif
25
+
22
26
#endregion Constants
23
27
24
28
#region Instance Fields
@@ -677,10 +681,27 @@ cache misses.
677
681
unzftab [ seqToUnseq [ tmp ] ] ++ ;
678
682
ll8 [ last ] = seqToUnseq [ tmp ] ;
679
683
680
- for ( int j = nextSym - 1 ; j > 0 ; -- j )
684
+ var j = nextSym - 1 ;
685
+
686
+ #if ! NETSTANDARD2_0 && ! NETFRAMEWORK
687
+ // This is vectorized memory move. Going from the back, we're taking chunks of array
688
+ // and write them at the new location shifted by one. Since chunks are VectorSize long,
689
+ // at the end we have to move "tail" (or head actually) of the array using a plain loop.
690
+ // If System.Numerics.Vector API is not available, the plain loop is used to do the whole copying.
691
+
692
+ while ( j >= VectorSize )
681
693
{
682
- yy [ j ] = yy [ j - 1 ] ;
694
+ var arrayPart = new System . Numerics . Vector < byte > ( yy , j - VectorSize ) ;
695
+ arrayPart . CopyTo ( yy , j - VectorSize + 1 ) ;
696
+ j -= VectorSize ;
683
697
}
698
+ #endif
699
+
700
+ while ( j > 0 )
701
+ {
702
+ yy [ j ] = yy [ -- j ] ;
703
+ }
704
+
684
705
yy [ 0 ] = tmp ;
685
706
686
707
if ( groupPos == 0 )
You can’t perform that action at this time.
0 commit comments