Skip to content

Commit

Permalink
Seal classes and avoid calling SuppressFinalize
Browse files Browse the repository at this point in the history
  • Loading branch information
brianpopow committed Nov 23, 2021
1 parent f93f102 commit 1450849
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 44 deletions.
24 changes: 2 additions & 22 deletions src/ImageSharp/Formats/Webp/Lossless/CostManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
internal class CostManager : IDisposable
internal sealed class CostManager : IDisposable
{
private bool disposed;

private CostInterval head;

private const int FreeIntervalsStartCount = 25;
Expand Down Expand Up @@ -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;
}
}

/// <inheritdoc />
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();
}
}
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Webp/Lossless/PixOrCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
23 changes: 2 additions & 21 deletions src/ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace SixLabors.ImageSharp.Formats.Webp.Lossless
{
internal class Vp8LHashChain : IDisposable
internal sealed class Vp8LHashChain : IDisposable
{
private const uint HashMultiplierHi = 0xc6a4a793u;

Expand All @@ -30,8 +30,6 @@ internal class Vp8LHashChain : IDisposable

private readonly MemoryAllocator memoryAllocator;

private bool disposed;

/// <summary>
/// Initializes a new instance of the <see cref="Vp8LHashChain"/> class.
/// </summary>
Expand Down Expand Up @@ -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;
}
}

/// <inheritdoc />
public void Dispose()
{
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
}
public void Dispose() => this.OffsetLength.Dispose();
}
}

0 comments on commit 1450849

Please sign in to comment.