@@ -109,12 +109,11 @@ private static void HistogramBuild(
109109 {
110110 int x = 0 , y = 0 ;
111111 int histoXSize = LosslessUtils . SubSampleSize ( xSize , histoBits ) ;
112- using List < PixOrCopy > . Enumerator backwardRefsEnumerator = backwardRefs . Refs . GetEnumerator ( ) ;
113- while ( backwardRefsEnumerator . MoveNext ( ) )
112+
113+ foreach ( PixOrCopy v in backwardRefs )
114114 {
115- PixOrCopy v = backwardRefsEnumerator . Current ;
116115 int ix = ( ( y >> histoBits ) * histoXSize ) + ( x >> histoBits ) ;
117- histograms [ ix ] . AddSinglePixOrCopy ( v , false ) ;
116+ histograms [ ix ] . AddSinglePixOrCopy ( in v , false ) ;
118117 x += v . Len ;
119118 while ( x >= xSize )
120119 {
@@ -217,7 +216,7 @@ private static void HistogramCombineEntropyBin(
217216 clusterMappings [ idx ] = ( ushort ) idx ;
218217 }
219218
220- List < int > indicesToRemove = new ( ) ;
219+ List < int > indicesToRemove = [ ] ;
221220 Vp8LStreaks stats = new ( ) ;
222221 Vp8LBitEntropy bitsEntropy = new ( ) ;
223222 for ( int idx = 0 ; idx < histograms . Count ; idx ++ )
@@ -345,7 +344,7 @@ private static bool HistogramCombineStochastic(Vp8LHistogramSet histograms, int
345344
346345 // Priority list of histogram pairs. Its size impacts the quality of the compression and the speed:
347346 // the smaller the faster but the worse for the compression.
348- List < HistogramPair > histoPriorityList = new ( ) ;
347+ List < HistogramPair > histoPriorityList = [ ] ;
349348 const int maxSize = 9 ;
350349
351350 // Fill the initial mapping.
@@ -465,7 +464,7 @@ private static bool HistogramCombineStochastic(Vp8LHistogramSet histograms, int
465464 }
466465 }
467466
468- HistoListUpdateHead ( histoPriorityList , p ) ;
467+ HistoListUpdateHead ( histoPriorityList , p , j ) ;
469468 j ++ ;
470469 }
471470
@@ -480,7 +479,7 @@ private static void HistogramCombineGreedy(Vp8LHistogramSet histograms)
480479 int histoSize = histograms . Count ( h => h != null ) ;
481480
482481 // Priority list of histogram pairs.
483- List < HistogramPair > histoPriorityList = new ( ) ;
482+ List < HistogramPair > histoPriorityList = [ ] ;
484483 int maxSize = histoSize * histoSize ;
485484 Vp8LStreaks stats = new ( ) ;
486485 Vp8LBitEntropy bitsEntropy = new ( ) ;
@@ -525,7 +524,7 @@ private static void HistogramCombineGreedy(Vp8LHistogramSet histograms)
525524 }
526525 else
527526 {
528- HistoListUpdateHead ( histoPriorityList , p ) ;
527+ HistoListUpdateHead ( histoPriorityList , p , i ) ;
529528 i ++ ;
530529 }
531530 }
@@ -647,7 +646,7 @@ private static double HistoPriorityListPush(
647646
648647 histoList . Add ( pair ) ;
649648
650- HistoListUpdateHead ( histoList , pair ) ;
649+ HistoListUpdateHead ( histoList , pair , histoList . Count - 1 ) ;
651650
652651 return pair . CostDiff ;
653652 }
@@ -674,13 +673,11 @@ private static void HistoListUpdatePair(
674673 /// <summary>
675674 /// Check whether a pair in the list should be updated as head or not.
676675 /// </summary>
677- private static void HistoListUpdateHead ( List < HistogramPair > histoList , HistogramPair pair )
676+ private static void HistoListUpdateHead ( List < HistogramPair > histoList , HistogramPair pair , int idx )
678677 {
679678 if ( pair . CostDiff < histoList [ 0 ] . CostDiff )
680679 {
681- // Replace the best pair.
682- int oldIdx = histoList . IndexOf ( pair ) ;
683- histoList [ oldIdx ] = histoList [ 0 ] ;
680+ histoList [ idx ] = histoList [ 0 ] ;
684681 histoList [ 0 ] = pair ;
685682 }
686683 }
0 commit comments