1212using BitFaster . Caching . Lru ;
1313using BitFaster . Caching . Scheduler ;
1414
15- #if ! NETSTANDARD2_0
16- using System . Buffers ;
17- #endif
18-
1915#if DEBUG
2016using System . Linq ;
2117using System . Text ;
@@ -56,9 +52,7 @@ public sealed class ConcurrentLfu<K, V> : ICache<K, V>, IAsyncCache<K, V>, IBoun
5652
5753 private readonly IScheduler scheduler ;
5854
59- #if NETSTANDARD2_0
6055 private readonly LfuNode < K , V > [ ] drainBuffer ;
61- #endif
6256
6357 /// <summary>
6458 /// Initializes a new instance of the ConcurrentLfu class with the specified capacity.
@@ -97,9 +91,7 @@ public ConcurrentLfu(int concurrencyLevel, int capacity, IScheduler scheduler, I
9791
9892 this . scheduler = scheduler ;
9993
100- #if NETSTANDARD2_0
10194 this . drainBuffer = new LfuNode < K , V > [ this . readBuffer . Capacity ] ;
102- #endif
10395 }
10496
10597 ///<inheritdoc/>
@@ -435,26 +427,25 @@ private void DrainBuffers()
435427 private bool Maintenance ( LfuNode < K , V > droppedWrite = null )
436428 {
437429 this . drainStatus . Set ( DrainStatus . ProcessingToIdle ) ;
438- var localDrainBuffer = RentDrainBuffer ( ) ;
439430
440431 // extract to a buffer before doing book keeping work, ~2x faster
441- int readCount = readBuffer . DrainTo ( localDrainBuffer ) ;
432+ int readCount = readBuffer . DrainTo ( this . drainBuffer ) ;
442433
443434 for ( int i = 0 ; i < readCount ; i ++ )
444435 {
445- this . cmSketch . Increment ( localDrainBuffer [ i ] . Key ) ;
436+ this . cmSketch . Increment ( this . drainBuffer [ i ] . Key ) ;
446437 }
447438
448439 for ( int i = 0 ; i < readCount ; i ++ )
449440 {
450- OnAccess ( localDrainBuffer [ i ] ) ;
441+ OnAccess ( this . drainBuffer [ i ] ) ;
451442 }
452443
453- int writeCount = this . writeBuffer . DrainTo ( new ArraySegment < LfuNode < K , V > > ( localDrainBuffer ) ) ;
444+ int writeCount = this . writeBuffer . DrainTo ( new ArraySegment < LfuNode < K , V > > ( this . drainBuffer ) ) ;
454445
455446 for ( int i = 0 ; i < writeCount ; i ++ )
456447 {
457- OnWrite ( localDrainBuffer [ i ] ) ;
448+ OnWrite ( this . drainBuffer [ i ] ) ;
458449 }
459450
460451 // we are done only when both buffers are empty
@@ -466,8 +457,6 @@ private bool Maintenance(LfuNode<K, V> droppedWrite = null)
466457 done = true ;
467458 }
468459
469- ReturnDrainBuffer ( localDrainBuffer ) ;
470-
471460 EvictEntries ( ) ;
472461 this . capacity . OptimizePartitioning ( this . metrics , this . cmSketch . ResetSampleSize ) ;
473462 ReFitProtected ( ) ;
@@ -687,22 +676,6 @@ private void ReFitProtected()
687676 }
688677 }
689678
690- private LfuNode < K , V > [ ] RentDrainBuffer ( )
691- {
692- #if ! NETSTANDARD2_0
693- return ArrayPool < LfuNode < K , V > > . Shared . Rent ( this . readBuffer . Capacity ) ;
694- #else
695- return drainBuffer ;
696- #endif
697- }
698-
699- private void ReturnDrainBuffer ( LfuNode < K , V > [ ] localDrainBuffer )
700- {
701- #if ! NETSTANDARD2_0
702- ArrayPool < LfuNode < K , V > > . Shared . Return ( localDrainBuffer ) ;
703- #endif
704- }
705-
706679 [ DebuggerDisplay ( "{Format(),nq}" ) ]
707680 private class DrainStatus
708681 {
0 commit comments