@@ -149,9 +149,8 @@ private static int CalculateBestCacheSize(
149149 }
150150
151151 // Find the cacheBits giving the lowest entropy.
152- for ( int idx = 0 ; idx < refs . Refs . Count ; idx ++ )
152+ foreach ( PixOrCopy v in refs )
153153 {
154- PixOrCopy v = refs . Refs [ idx ] ;
155154 if ( v . IsLiteral ( ) )
156155 {
157156 uint pix = bgra [ pos ++ ] ;
@@ -387,7 +386,7 @@ private static void BackwardReferencesHashChainFollowChosenPath(ReadOnlySpan<uin
387386 colorCache = new ColorCache ( cacheBits ) ;
388387 }
389388
390- backwardRefs . Refs . Clear ( ) ;
389+ backwardRefs . Clear ( ) ;
391390 for ( int ix = 0 ; ix < chosenPathSize ; ix ++ )
392391 {
393392 int len = chosenPath [ ix ] ;
@@ -479,7 +478,7 @@ private static void BackwardReferencesLz77(int xSize, int ySize, ReadOnlySpan<ui
479478 colorCache = new ColorCache ( cacheBits ) ;
480479 }
481480
482- refs . Refs . Clear ( ) ;
481+ refs . Clear ( ) ;
483482 for ( int i = 0 ; i < pixCount ; )
484483 {
485484 // 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
734733 colorCache = new ColorCache ( cacheBits ) ;
735734 }
736735
737- refs . Refs . Clear ( ) ;
736+ refs . Clear ( ) ;
738737
739738 // Add first pixel as literal.
740739 AddSingleLiteral ( bgra [ 0 ] , useColorCache , colorCache , refs ) ;
@@ -780,19 +779,16 @@ private static void BackwardRefsWithLocalCache(ReadOnlySpan<uint> bgra, int cach
780779 {
781780 int pixelIndex = 0 ;
782781 ColorCache colorCache = new ColorCache ( cacheBits ) ;
783- for ( int idx = 0 ; idx < refs . Refs . Count ; idx ++ )
782+ foreach ( ref PixOrCopy v in refs )
784783 {
785- PixOrCopy v = refs . Refs [ idx ] ;
786784 if ( v . IsLiteral ( ) )
787785 {
788786 uint bgraLiteral = v . BgraOrDistance ;
789787 int ix = colorCache . Contains ( bgraLiteral ) ;
790788 if ( ix >= 0 )
791789 {
792790 // Color cache contains bgraLiteral
793- v . Mode = PixOrCopyMode . CacheIdx ;
794- v . BgraOrDistance = ( uint ) ix ;
795- v . Len = 1 ;
791+ v = PixOrCopy . CreateCacheIdx ( ix ) ;
796792 }
797793 else
798794 {
@@ -814,14 +810,13 @@ private static void BackwardRefsWithLocalCache(ReadOnlySpan<uint> bgra, int cach
814810
815811 private static void BackwardReferences2DLocality ( int xSize , Vp8LBackwardRefs refs )
816812 {
817- using List < PixOrCopy > . Enumerator c = refs . Refs . GetEnumerator ( ) ;
818- while ( c . MoveNext ( ) )
813+ foreach ( ref PixOrCopy v in refs )
819814 {
820- if ( c . Current . IsCopy ( ) )
815+ if ( v . IsCopy ( ) )
821816 {
822- int dist = ( int ) c . Current . BgraOrDistance ;
817+ int dist = ( int ) v . BgraOrDistance ;
823818 int transformedDist = DistanceToPlaneCode ( xSize , dist ) ;
824- c . Current . BgraOrDistance = ( uint ) transformedDist ;
819+ v = PixOrCopy . CreateCopy ( ( uint ) transformedDist , v . Len ) ;
825820 }
826821 }
827822 }
0 commit comments