Skip to content

Commit

Permalink
Declare readonly members for mutable structs
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Jan 19, 2022
1 parent ef20668 commit 059f764
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ internal Enumerator(HttpRequestHeaders collection)
: default;
}

public KeyValuePair<string, StringValues> Current => _current;
public readonly KeyValuePair<string, StringValues> Current => _current;

object IEnumerator.Current => _current;
readonly object IEnumerator.Current => _current;

public void Dispose()
public readonly void Dispose()
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ internal Enumerator(HttpResponseHeaders collection)
: default;
}

public KeyValuePair<string, StringValues> Current => _current;
public readonly KeyValuePair<string, StringValues> Current => _current;

internal KnownHeaderType CurrentKnownType => _currentKnownType;
internal readonly KnownHeaderType CurrentKnownType => _currentKnownType;

object IEnumerator.Current => _current;
readonly object IEnumerator.Current => _current;

public void Dispose()
public readonly void Dispose()
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ internal Enumerator(HttpResponseTrailers collection)
: default;
}

public KeyValuePair<string, StringValues> Current => _current;
public readonly KeyValuePair<string, StringValues> Current => _current;

internal KnownHeaderType CurrentKnownType => _currentKnownType;
internal readonly KnownHeaderType CurrentKnownType => _currentKnownType;

object IEnumerator.Current => _current;
readonly object IEnumerator.Current => _current;

public void Dispose()
public readonly void Dispose()
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public HttpVersionAndMethod(HttpMethod method, int methodEnd)

public HttpVersion Version
{
get => (HttpVersion)(sbyte)(byte)_versionAndMethod;
readonly get => (HttpVersion)(sbyte)(byte)_versionAndMethod;
set => _versionAndMethod = (_versionAndMethod & ~0xFFul) | (byte)value;
}

public HttpMethod Method => (HttpMethod)(byte)(_versionAndMethod >> 8);
public readonly HttpMethod Method => (HttpMethod)(byte)(_versionAndMethod >> 8);

public int MethodEnd => (int)(uint)(_versionAndMethod >> 32);
public readonly int MethodEnd => (int)(uint)(_versionAndMethod >> 32);
}

public readonly struct TargetOffsetPathLength
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public FlowControl(uint initialWindowSize)
IsAborted = false;
}

public int Available { get; private set; }
public bool IsAborted { get; private set; }
public int Available { readonly get; private set; }
public bool IsAborted { readonly get; private set; }

public void Advance(int bytes)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/Kestrel/shared/PooledStreamStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public PooledStreamStack(int size)
_size = 0;
}

public int Count => _size;
public readonly int Count => _size;

public bool TryPop([NotNullWhen(true)] out TValue? result)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/Buffers/BufferSegmentStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public BufferSegmentStack(int size)
_size = 0;
}

public int Count => _size;
public readonly int Count => _size;

public bool TryPop([NotNullWhen(true)] out BufferSegment? result)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/CertificateGeneration/CertificateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ internal class UserCancelledTrustException : Exception
{
}

internal struct CheckCertificateStateResult
internal readonly struct CheckCertificateStateResult
{
public bool Success { get; }
public string? FailureMessage { get; }
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/ServerInfrastructure/BufferWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public BufferWriter(T output)
/// <summary>
/// Gets the result of the last call to <see cref="IBufferWriter{T}.GetSpan(int)"/>.
/// </summary>
public Span<byte> Span => _span;
public readonly Span<byte> Span => _span;

/// <summary>
/// Gets the total number of bytes written with this writer.
/// </summary>
public long BytesCommitted => _bytesCommitted;
public readonly long BytesCommitted => _bytesCommitted;

/// <summary>
/// Calls <see cref="IBufferWriter{T}.Advance(int)"/> on the underlying writer
Expand Down

0 comments on commit 059f764

Please sign in to comment.