fix(build): Attempt to fix possible nullable warnings as errors with releases (#418)

This commit is contained in:
Kamron Batman 2021-01-18 11:52:31 -08:00 committed by GitHub
parent 08f05afd01
commit 87764ca968
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 11 deletions

View file

@ -29,7 +29,7 @@ namespace System.Buffers
public ref struct SpanWriter
{
private readonly bool _resize;
private byte[]? _arrayToReturnToPool;
private byte[] _arrayToReturnToPool;
private Span<byte> _buffer;
private int _position;
@ -81,7 +81,7 @@ namespace System.Buffers
_buffer.SliceToLength(BytesWritten).CopyTo(poolArray);
byte[]? toReturn = _arrayToReturnToPool;
byte[] toReturn = _arrayToReturnToPool;
_buffer = _arrayToReturnToPool = poolArray;
if (toReturn != null)
{

View file

@ -11,7 +11,7 @@ namespace Server.Buffers
{
public ref struct ValueStringBuilder
{
private char[]? _arrayToReturnToPool;
private char[] _arrayToReturnToPool;
private Span<char> _chars;
// If this ctor is used, you cannot pass in stackalloc ROS for append/replace.
@ -124,7 +124,7 @@ namespace Server.Buffers
Length += count;
}
public void Insert(int index, string? s)
public void Insert(int index, string s)
{
if (s == null)
{
@ -160,7 +160,7 @@ namespace Server.Buffers
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Append(string? s)
public void Append(string s)
{
if (s == null)
{
@ -180,7 +180,7 @@ namespace Server.Buffers
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AppendLine(string? s)
public void AppendLine(string s)
{
if (s == null)
{
@ -275,6 +275,7 @@ namespace Server.Buffers
Append(c);
}
#nullable enable
/// <summary>
/// Resize the internal buffer either by doubling current buffer size or
/// by adding <paramref name="additionalCapacityBeyondPos"/> to
@ -290,7 +291,7 @@ namespace Server.Buffers
_chars.SliceToLength(Length).CopyTo(poolArray);
char[]? toReturn = _arrayToReturnToPool;
char[] toReturn = _arrayToReturnToPool;
_chars = _arrayToReturnToPool = poolArray;
if (toReturn != null)
{
@ -301,13 +302,14 @@ namespace Server.Buffers
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
char[]? toReturn = _arrayToReturnToPool;
char[] toReturn = _arrayToReturnToPool;
this = default; // for safety, to avoid using pooled array if this instance is erroneously appended to again
if (toReturn != null)
{
ArrayPool<char>.Shared.Return(toReturn);
}
}
#nullable disable
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ReplaceAny(ReadOnlySpan<char> oldChars, ReadOnlySpan<char> newChars, int startIndex, int count)