diff --git a/BitFaster.Caching/Lfu/ConcurrentLfu.cs b/BitFaster.Caching/Lfu/ConcurrentLfu.cs index 1b3607c4..c432fa3e 100644 --- a/BitFaster.Caching/Lfu/ConcurrentLfu.cs +++ b/BitFaster.Caching/Lfu/ConcurrentLfu.cs @@ -12,10 +12,6 @@ using BitFaster.Caching.Lru; using BitFaster.Caching.Scheduler; -#if !NETSTANDARD2_0 -using System.Buffers; -#endif - #if DEBUG using System.Linq; using System.Text; @@ -56,9 +52,7 @@ public sealed class ConcurrentLfu : ICache, IAsyncCache, IBoun private readonly IScheduler scheduler; -#if NETSTANDARD2_0 private readonly LfuNode[] drainBuffer; -#endif /// /// 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 this.scheduler = scheduler; -#if NETSTANDARD2_0 this.drainBuffer = new LfuNode[this.readBuffer.Capacity]; -#endif } /// @@ -435,26 +427,25 @@ private void DrainBuffers() private bool Maintenance(LfuNode droppedWrite = null) { this.drainStatus.Set(DrainStatus.ProcessingToIdle); - var localDrainBuffer = RentDrainBuffer(); // extract to a buffer before doing book keeping work, ~2x faster - int readCount = readBuffer.DrainTo(localDrainBuffer); + int readCount = readBuffer.DrainTo(this.drainBuffer); for (int i = 0; i < readCount; i++) { - this.cmSketch.Increment(localDrainBuffer[i].Key); + this.cmSketch.Increment(this.drainBuffer[i].Key); } for (int i = 0; i < readCount; i++) { - OnAccess(localDrainBuffer[i]); + OnAccess(this.drainBuffer[i]); } - int writeCount = this.writeBuffer.DrainTo(new ArraySegment>(localDrainBuffer)); + int writeCount = this.writeBuffer.DrainTo(new ArraySegment>(this.drainBuffer)); for (int i = 0; i < writeCount; i++) { - OnWrite(localDrainBuffer[i]); + OnWrite(this.drainBuffer[i]); } // we are done only when both buffers are empty @@ -466,8 +457,6 @@ private bool Maintenance(LfuNode droppedWrite = null) done = true; } - ReturnDrainBuffer(localDrainBuffer); - EvictEntries(); this.capacity.OptimizePartitioning(this.metrics, this.cmSketch.ResetSampleSize); ReFitProtected(); @@ -687,22 +676,6 @@ private void ReFitProtected() } } - private LfuNode[] RentDrainBuffer() - { -#if !NETSTANDARD2_0 - return ArrayPool>.Shared.Rent(this.readBuffer.Capacity); -#else - return drainBuffer; -#endif - } - - private void ReturnDrainBuffer(LfuNode[] localDrainBuffer) - { -#if !NETSTANDARD2_0 - ArrayPool>.Shared.Return(localDrainBuffer); -#endif - } - [DebuggerDisplay("{Format(),nq}")] private class DrainStatus {