Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make internal & private classes sealed when possible. Avoid double lookup in dictionary #881

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ICSharpCode.SharpZipLib/Core/StringBuilderPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace ICSharpCode.SharpZipLib.Core
{
internal class StringBuilderPool
internal sealed class StringBuilderPool
{
public static StringBuilderPool Instance { get; } = new StringBuilderPool();
private readonly ConcurrentQueue<StringBuilder> pool = new ConcurrentQueue<StringBuilder>();
Expand Down
4 changes: 2 additions & 2 deletions src/ICSharpCode.SharpZipLib/Encryption/PkzipClassic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected void Reset()
/// <summary>
/// PkzipClassic CryptoTransform for encryption.
/// </summary>
internal class PkzipClassicEncryptCryptoTransform : PkzipClassicCryptoBase, ICryptoTransform
internal sealed class PkzipClassicEncryptCryptoTransform : PkzipClassicCryptoBase, ICryptoTransform
{
/// <summary>
/// Initialise a new instance of <see cref="PkzipClassicEncryptCryptoTransform"></see>
Expand Down Expand Up @@ -240,7 +240,7 @@ public void Dispose()
/// <summary>
/// PkzipClassic CryptoTransform for decryption.
/// </summary>
internal class PkzipClassicDecryptCryptoTransform : PkzipClassicCryptoBase, ICryptoTransform
internal sealed class PkzipClassicDecryptCryptoTransform : PkzipClassicCryptoBase, ICryptoTransform
{
/// <summary>
/// Initialise a new instance of <see cref="PkzipClassicDecryptCryptoTransform"></see>.
Expand Down
2 changes: 1 addition & 1 deletion src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace ICSharpCode.SharpZipLib.Encryption
/// Based on information from http://www.winzip.com/aes_info.htm
/// and http://www.gladman.me.uk/cryptography_technology/fileencrypt/
/// </remarks>
internal class ZipAESStream : CryptoStream
internal sealed class ZipAESStream : CryptoStream
{
/// <summary>
/// Constructor
Expand Down
2 changes: 1 addition & 1 deletion src/ICSharpCode.SharpZipLib/Encryption/ZipAESTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ICSharpCode.SharpZipLib.Encryption
/// <summary>
/// Transforms stream using AES in CTR mode
/// </summary>
internal class ZipAESTransform : ICryptoTransform
internal sealed class ZipAESTransform : ICryptoTransform
{
private const int PWD_VER_LENGTH = 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class DeflaterHuffman
private static short[] staticDCodes;
private static byte[] staticDLength;

private class Tree
private sealed class Tree
{
#region Instance Fields

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ICSharpCode.SharpZipLib.Zip.Compression
{
internal class InflaterDynHeader
internal sealed class InflaterDynHeader
{
#region Constants

Expand Down
18 changes: 9 additions & 9 deletions src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2679,9 +2679,9 @@ private void CopyEntryDataDirect(ZipUpdate update, Stream stream, bool updateCrc
private int FindExistingUpdate(ZipEntry entry)
{
int result = -1;
if (updateIndex_.ContainsKey(entry.Name))
if (updateIndex_.TryGetValue(entry.Name, out int value))
{
result = (int)updateIndex_[entry.Name];
result = value;
}
/*
// This is slow like the coming of the next ice age but takes less storage and may be useful
Expand All @@ -2705,9 +2705,9 @@ private int FindExistingUpdate(string fileName, bool isEntryName = false)

string convertedName = !isEntryName ? GetTransformedFileName(fileName) : fileName;

if (updateIndex_.ContainsKey(convertedName))
if (updateIndex_.TryGetValue(convertedName, out int value))
{
result = (int)updateIndex_[convertedName];
result = value;
}

/*
Expand Down Expand Up @@ -3030,7 +3030,7 @@ private void UpdateCommentOnly()
/// <summary>
/// Class used to sort updates.
/// </summary>
private class UpdateComparer : IComparer<ZipUpdate>
private sealed class UpdateComparer : IComparer<ZipUpdate>
{
/// <summary>
/// Compares two objects and returns a value indicating whether one is
Expand Down Expand Up @@ -3252,7 +3252,7 @@ private void CheckUpdating()
/// <summary>
/// Represents a pending update to a Zip file.
/// </summary>
private class ZipUpdate
private sealed class ZipUpdate
{
#region Constructors

Expand Down Expand Up @@ -3911,7 +3911,7 @@ private static void WriteEncryptionHeader(Stream stream, long crcValue)
/// <summary>
/// Represents a string from a <see cref="ZipFile"/> which is stored as an array of bytes.
/// </summary>
private class ZipString
private sealed class ZipString
{
#region Constructors

Expand Down Expand Up @@ -4086,7 +4086,7 @@ public void Dispose()
/// An <see cref="UncompressedStream"/> is a stream that you can write uncompressed data
/// to and flush, but cannot read, seek or do anything else to.
/// </summary>
private class UncompressedStream : Stream
private sealed class UncompressedStream : Stream
{
#region Constructors

Expand Down Expand Up @@ -4241,7 +4241,7 @@ private readonly
/// A <see cref="PartialInputStream"/> is an <see cref="InflaterInputStream"/>
/// whose data is only a part or subsection of a file.
/// </summary>
private class PartialInputStream : Stream
private sealed class PartialInputStream : Stream
{
#region Constructors

Expand Down