From 14508498d9f0d709e31d4d4e4e44a740cb3353c2 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 23 Nov 2021 09:00:33 +0100 Subject: [PATCH] Seal classes and avoid calling SuppressFinalize --- .../Formats/Webp/Lossless/CostManager.cs | 24 ++----------------- .../Formats/Webp/Lossless/PixOrCopy.cs | 2 +- .../Formats/Webp/Lossless/Vp8LHashChain.cs | 23 ++---------------- 3 files changed, 5 insertions(+), 44 deletions(-) diff --git a/src/ImageSharp/Formats/Webp/Lossless/CostManager.cs b/src/ImageSharp/Formats/Webp/Lossless/CostManager.cs index 3ee1021386..c121a41a1a 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/CostManager.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/CostManager.cs @@ -13,10 +13,8 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless /// It caches the different CostCacheInterval, caches the different /// GetLengthCost(costModel, k) in costCache and the CostInterval's. /// - internal class CostManager : IDisposable + internal sealed class CostManager : IDisposable { - private bool disposed; - private CostInterval head; private const int FreeIntervalsStartCount = 25; @@ -328,25 +326,7 @@ private void UpdateCost(int i, int position, float cost) } } - protected virtual void Dispose(bool disposing) - { - if (!this.disposed) - { - if (disposing) - { - this.Costs.Dispose(); - } - - this.disposed = true; - } - } - /// - public void Dispose() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - this.Dispose(disposing: true); - GC.SuppressFinalize(this); - } + public void Dispose() => this.Costs.Dispose(); } } diff --git a/src/ImageSharp/Formats/Webp/Lossless/PixOrCopy.cs b/src/ImageSharp/Formats/Webp/Lossless/PixOrCopy.cs index 6cd109121d..96cdc3cbc5 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/PixOrCopy.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/PixOrCopy.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless { [DebuggerDisplay("Mode: {Mode}, Len: {Len}, BgraOrDistance: {BgraOrDistance}")] - internal class PixOrCopy + internal sealed class PixOrCopy { public PixOrCopyMode Mode { get; set; } diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs index 2aa35e392e..1bc7613a90 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless { - internal class Vp8LHashChain : IDisposable + internal sealed class Vp8LHashChain : IDisposable { private const uint HashMultiplierHi = 0xc6a4a793u; @@ -30,8 +30,6 @@ internal class Vp8LHashChain : IDisposable private readonly MemoryAllocator memoryAllocator; - private bool disposed; - /// /// Initializes a new instance of the class. /// @@ -288,24 +286,7 @@ private static int GetWindowSizeForHashChain(int quality, int xSize) return maxWindowSize > WindowSize ? WindowSize : maxWindowSize; } - protected virtual void Dispose(bool disposing) - { - if (!this.disposed) - { - if (disposing) - { - this.OffsetLength.Dispose(); - } - - this.disposed = true; - } - } - /// - public void Dispose() - { - this.Dispose(disposing: true); - GC.SuppressFinalize(this); - } + public void Dispose() => this.OffsetLength.Dispose(); } }