@@ -149,9 +149,8 @@ private static int CalculateBestCacheSize(
149
149
}
150
150
151
151
// Find the cacheBits giving the lowest entropy.
152
- for ( int idx = 0 ; idx < refs . Refs . Count ; idx ++ )
152
+ foreach ( PixOrCopy v in refs )
153
153
{
154
- PixOrCopy v = refs . Refs [ idx ] ;
155
154
if ( v . IsLiteral ( ) )
156
155
{
157
156
uint pix = bgra [ pos ++ ] ;
@@ -387,7 +386,7 @@ private static void BackwardReferencesHashChainFollowChosenPath(ReadOnlySpan<uin
387
386
colorCache = new ColorCache ( cacheBits ) ;
388
387
}
389
388
390
- backwardRefs . Refs . Clear ( ) ;
389
+ backwardRefs . Clear ( ) ;
391
390
for ( int ix = 0 ; ix < chosenPathSize ; ix ++ )
392
391
{
393
392
int len = chosenPath [ ix ] ;
@@ -479,7 +478,7 @@ private static void BackwardReferencesLz77(int xSize, int ySize, ReadOnlySpan<ui
479
478
colorCache = new ColorCache ( cacheBits ) ;
480
479
}
481
480
482
- refs . Refs . Clear ( ) ;
481
+ refs . Clear ( ) ;
483
482
for ( int i = 0 ; i < pixCount ; )
484
483
{
485
484
// Alternative #1: Code the pixels starting at 'i' using backward reference.
@@ -734,7 +733,7 @@ private static void BackwardReferencesRle(int xSize, int ySize, ReadOnlySpan<uin
734
733
colorCache = new ColorCache ( cacheBits ) ;
735
734
}
736
735
737
- refs . Refs . Clear ( ) ;
736
+ refs . Clear ( ) ;
738
737
739
738
// Add first pixel as literal.
740
739
AddSingleLiteral ( bgra [ 0 ] , useColorCache , colorCache , refs ) ;
@@ -780,19 +779,16 @@ private static void BackwardRefsWithLocalCache(ReadOnlySpan<uint> bgra, int cach
780
779
{
781
780
int pixelIndex = 0 ;
782
781
ColorCache colorCache = new ColorCache ( cacheBits ) ;
783
- for ( int idx = 0 ; idx < refs . Refs . Count ; idx ++ )
782
+ foreach ( ref PixOrCopy v in refs )
784
783
{
785
- PixOrCopy v = refs . Refs [ idx ] ;
786
784
if ( v . IsLiteral ( ) )
787
785
{
788
786
uint bgraLiteral = v . BgraOrDistance ;
789
787
int ix = colorCache . Contains ( bgraLiteral ) ;
790
788
if ( ix >= 0 )
791
789
{
792
790
// Color cache contains bgraLiteral
793
- v . Mode = PixOrCopyMode . CacheIdx ;
794
- v . BgraOrDistance = ( uint ) ix ;
795
- v . Len = 1 ;
791
+ v = PixOrCopy . CreateCacheIdx ( ix ) ;
796
792
}
797
793
else
798
794
{
@@ -814,14 +810,13 @@ private static void BackwardRefsWithLocalCache(ReadOnlySpan<uint> bgra, int cach
814
810
815
811
private static void BackwardReferences2DLocality ( int xSize , Vp8LBackwardRefs refs )
816
812
{
817
- using List < PixOrCopy > . Enumerator c = refs . Refs . GetEnumerator ( ) ;
818
- while ( c . MoveNext ( ) )
813
+ foreach ( ref PixOrCopy v in refs )
819
814
{
820
- if ( c . Current . IsCopy ( ) )
815
+ if ( v . IsCopy ( ) )
821
816
{
822
- int dist = ( int ) c . Current . BgraOrDistance ;
817
+ int dist = ( int ) v . BgraOrDistance ;
823
818
int transformedDist = DistanceToPlaneCode ( xSize , dist ) ;
824
- c . Current . BgraOrDistance = ( uint ) transformedDist ;
819
+ v = PixOrCopy . CreateCopy ( ( uint ) transformedDist , v . Len ) ;
825
820
}
826
821
}
827
822
}
0 commit comments