File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed
src/ICSharpCode.SharpZipLib/BZip2 Expand file tree Collapse file tree 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
1919 private const int NO_RAND_PART_B_STATE = 6 ;
2020 private const int NO_RAND_PART_C_STATE = 7 ;
2121
22+ #if NETSTANDARD2_1
23+ private static readonly int VectorSize = System . Numerics . Vector < byte > . Count ;
24+ #endif
25+
2226 #endregion Constants
2327
2428 #region Instance Fields
@@ -677,10 +681,27 @@ cache misses.
677681 unzftab [ seqToUnseq [ tmp ] ] ++ ;
678682 ll8 [ last ] = seqToUnseq [ tmp ] ;
679683
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 )
681693 {
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 ;
683697 }
698+ #endif
699+
700+ while ( j > 0 )
701+ {
702+ yy [ j ] = yy [ -- j ] ;
703+ }
704+
684705 yy [ 0 ] = tmp ;
685706
686707 if ( groupPos == 0 )
You can’t perform that action at this time.
0 commit comments