chore: Use var everywhere (#2294)
This commit is contained in:
parent
0b34cc4417
commit
ebaf104935
267 changed files with 873 additions and 873 deletions
|
|
@ -84,7 +84,7 @@ public ref struct RawInterpolatedStringHandler
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] // used only on a few hot paths
|
||||
public void Clear()
|
||||
{
|
||||
char[]? toReturn = _arrayToReturnToPool;
|
||||
var toReturn = _arrayToReturnToPool;
|
||||
this = default; // defensive clear
|
||||
if (toReturn is not null)
|
||||
{
|
||||
|
|
@ -102,8 +102,8 @@ public ref struct RawInterpolatedStringHandler
|
|||
{
|
||||
if (value.Length == 1)
|
||||
{
|
||||
Span<char> chars = _chars;
|
||||
int pos = _pos;
|
||||
var chars = _chars;
|
||||
var pos = _pos;
|
||||
if ((uint)pos < (uint)chars.Length)
|
||||
{
|
||||
chars[pos] = value[0];
|
||||
|
|
@ -312,7 +312,7 @@ public ref struct RawInterpolatedStringHandler
|
|||
/// <param name="alignment">Minimum number of characters that should be written for this value. If the value is negative, it indicates left-aligned and the required minimum is the absolute value.</param>
|
||||
public void AppendFormatted<T>(T value, int alignment)
|
||||
{
|
||||
int startingPos = _pos;
|
||||
var startingPos = _pos;
|
||||
AppendFormatted(value);
|
||||
if (alignment != 0)
|
||||
{
|
||||
|
|
@ -326,7 +326,7 @@ public ref struct RawInterpolatedStringHandler
|
|||
/// <param name="alignment">Minimum number of characters that should be written for this value. If the value is negative, it indicates left-aligned and the required minimum is the absolute value.</param>
|
||||
public void AppendFormatted<T>(T value, int alignment, string? format)
|
||||
{
|
||||
int startingPos = _pos;
|
||||
var startingPos = _pos;
|
||||
AppendFormatted(value, format);
|
||||
if (alignment != 0)
|
||||
{
|
||||
|
|
@ -357,14 +357,14 @@ public ref struct RawInterpolatedStringHandler
|
|||
/// <param name="format">The format string.</param>
|
||||
public void AppendFormatted(ReadOnlySpan<char> value, int alignment = 0, string? format = null)
|
||||
{
|
||||
bool leftAlign = false;
|
||||
var leftAlign = false;
|
||||
if (alignment < 0)
|
||||
{
|
||||
leftAlign = true;
|
||||
alignment = -alignment;
|
||||
}
|
||||
|
||||
int paddingRequired = alignment - value.Length;
|
||||
var paddingRequired = alignment - value.Length;
|
||||
if (paddingRequired <= 0)
|
||||
{
|
||||
// The value is as large or larger than the required amount of padding,
|
||||
|
|
@ -477,7 +477,7 @@ public ref struct RawInterpolatedStringHandler
|
|||
Debug.Assert(_hasCustomFormatter);
|
||||
Debug.Assert(_provider != null);
|
||||
|
||||
ICustomFormatter? formatter = (ICustomFormatter?)_provider.GetFormat(typeof(ICustomFormatter));
|
||||
var formatter = (ICustomFormatter?)_provider.GetFormat(typeof(ICustomFormatter));
|
||||
Debug.Assert(formatter != null, "An incorrectly written provider said it implemented ICustomFormatter, and then didn't");
|
||||
|
||||
if (formatter?.Format(format, value, _provider) is string customFormatted)
|
||||
|
|
@ -494,16 +494,16 @@ public ref struct RawInterpolatedStringHandler
|
|||
Debug.Assert(startingPos >= 0 && startingPos <= _pos);
|
||||
Debug.Assert(alignment != 0);
|
||||
|
||||
int charsWritten = _pos - startingPos;
|
||||
var charsWritten = _pos - startingPos;
|
||||
|
||||
bool leftAlign = false;
|
||||
var leftAlign = false;
|
||||
if (alignment < 0)
|
||||
{
|
||||
leftAlign = true;
|
||||
alignment = -alignment;
|
||||
}
|
||||
|
||||
int paddingNeeded = alignment - charsWritten;
|
||||
var paddingNeeded = alignment - charsWritten;
|
||||
if (paddingNeeded > 0)
|
||||
{
|
||||
EnsureCapacityForAdditionalChars(paddingNeeded);
|
||||
|
|
@ -583,13 +583,13 @@ public ref struct RawInterpolatedStringHandler
|
|||
// ints that could technically overflow if someone tried to, for example, append a huge string to a huge string, we also clamp to int.MaxValue.
|
||||
// Even if the array creation fails in such a case, we may later fail in ToStringAndClear.
|
||||
|
||||
uint newCapacity = Math.Max(requiredMinCapacity, Math.Min((uint)_chars.Length * 2, 0x3FFFFFDF));
|
||||
int arraySize = (int)Math.Clamp(newCapacity, MinimumArrayPoolLength, int.MaxValue);
|
||||
var newCapacity = Math.Max(requiredMinCapacity, Math.Min((uint)_chars.Length * 2, 0x3FFFFFDF));
|
||||
var arraySize = (int)Math.Clamp(newCapacity, MinimumArrayPoolLength, int.MaxValue);
|
||||
|
||||
char[] newArray = STArrayPool<char>.Shared.Rent(arraySize);
|
||||
var newArray = STArrayPool<char>.Shared.Rent(arraySize);
|
||||
_chars[.._pos].CopyTo(newArray);
|
||||
|
||||
char[]? toReturn = _arrayToReturnToPool;
|
||||
var toReturn = _arrayToReturnToPool;
|
||||
_chars = _arrayToReturnToPool = newArray;
|
||||
|
||||
if (toReturn is not null)
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ public class STArrayPool<T> : ArrayPool<T>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static int GetMaxSizeForBucket(int binIndex)
|
||||
{
|
||||
int maxSize = 16 << binIndex;
|
||||
var maxSize = 16 << binIndex;
|
||||
Debug.Assert(maxSize >= 0);
|
||||
return maxSize;
|
||||
}
|
||||
|
|
@ -259,7 +259,7 @@ public class STArrayPool<T> : ArrayPool<T>
|
|||
|
||||
internal static MemoryPressure GetMemoryPressure()
|
||||
{
|
||||
GCMemoryInfo memoryInfo = GC.GetGCMemoryInfo();
|
||||
var memoryInfo = GC.GetGCMemoryInfo();
|
||||
|
||||
if (memoryInfo.MemoryLoadBytes >= memoryInfo.HighMemoryLoadThresholdBytes * 0.90)
|
||||
{
|
||||
|
|
@ -333,7 +333,7 @@ public class STArrayPool<T> : ArrayPool<T>
|
|||
return;
|
||||
}
|
||||
|
||||
int trimCount = 1;
|
||||
var trimCount = 1;
|
||||
switch (pressure)
|
||||
{
|
||||
case MemoryPressure.Medium:
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ public ref struct ValueStringBuilder
|
|||
Grow(count);
|
||||
}
|
||||
|
||||
int remaining = _length - index;
|
||||
var remaining = _length - index;
|
||||
_chars.Slice(index, remaining).CopyTo(_chars[(index + count)..]);
|
||||
_chars.Slice(index, count).Fill(value);
|
||||
_length += count;
|
||||
|
|
@ -165,14 +165,14 @@ public ref struct ValueStringBuilder
|
|||
return;
|
||||
}
|
||||
|
||||
int count = s.Length;
|
||||
var count = s.Length;
|
||||
|
||||
if (_length > _chars.Length - count)
|
||||
{
|
||||
Grow(count);
|
||||
}
|
||||
|
||||
int remaining = _length - index;
|
||||
var remaining = _length - index;
|
||||
_chars.Slice(index, remaining).CopyTo(_chars[(index + count)..]);
|
||||
s.AsSpan().CopyTo(_chars[index..]);
|
||||
_length += count;
|
||||
|
|
@ -184,7 +184,7 @@ public ref struct ValueStringBuilder
|
|||
{
|
||||
if (value is ISpanFormattable)
|
||||
{
|
||||
Span<char> destination = _chars[_length..];
|
||||
var destination = _chars[_length..];
|
||||
int charsWritten;
|
||||
while (!((ISpanFormattable)value).TryFormat(destination, out charsWritten, format, default))
|
||||
{
|
||||
|
|
@ -229,7 +229,7 @@ public ref struct ValueStringBuilder
|
|||
return;
|
||||
}
|
||||
|
||||
int pos = _length;
|
||||
var pos = _length;
|
||||
if (s.Length == 1 && (uint)pos < (uint)_chars.Length) // very common case, e.g. appending strings from NumberFormatInfo like separators, percent symbols, etc.
|
||||
{
|
||||
_chars[pos] = s[0];
|
||||
|
|
@ -265,7 +265,7 @@ public ref struct ValueStringBuilder
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void AppendSlow(string? s)
|
||||
{
|
||||
int pos = _length;
|
||||
var pos = _length;
|
||||
if (pos > _chars.Length - s.Length)
|
||||
{
|
||||
Grow(s.Length);
|
||||
|
|
@ -283,8 +283,8 @@ public ref struct ValueStringBuilder
|
|||
Grow(count);
|
||||
}
|
||||
|
||||
Span<char> dst = _chars.Slice(_length, count);
|
||||
for (int i = 0; i < dst.Length; i++)
|
||||
var dst = _chars.Slice(_length, count);
|
||||
for (var i = 0; i < dst.Length; i++)
|
||||
{
|
||||
dst[i] = c;
|
||||
}
|
||||
|
|
@ -294,14 +294,14 @@ public ref struct ValueStringBuilder
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe void Append(char* value, int length)
|
||||
{
|
||||
int pos = _length;
|
||||
var pos = _length;
|
||||
if (pos > _chars.Length - length)
|
||||
{
|
||||
Grow(length);
|
||||
}
|
||||
|
||||
Span<char> dst = _chars.Slice(_length, length);
|
||||
for (int i = 0; i < dst.Length; i++)
|
||||
var dst = _chars.Slice(_length, length);
|
||||
for (var i = 0; i < dst.Length; i++)
|
||||
{
|
||||
dst[i] = *value++;
|
||||
}
|
||||
|
|
@ -311,7 +311,7 @@ public ref struct ValueStringBuilder
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Append(scoped ReadOnlySpan<char> value)
|
||||
{
|
||||
int pos = _length;
|
||||
var pos = _length;
|
||||
if (pos > _chars.Length - value.Length)
|
||||
{
|
||||
Grow(value.Length);
|
||||
|
|
@ -324,7 +324,7 @@ public ref struct ValueStringBuilder
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Span<char> AppendSpan(int length)
|
||||
{
|
||||
int origPos = _length;
|
||||
var origPos = _length;
|
||||
if (origPos > _chars.Length - length)
|
||||
{
|
||||
Grow(length);
|
||||
|
|
@ -345,11 +345,11 @@ public ref struct ValueStringBuilder
|
|||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private void Grow(int additionalCapacityBeyondPos)
|
||||
{
|
||||
char[] poolArray = ArrayPool.Rent(Math.Max(_length + additionalCapacityBeyondPos, _chars.Length * 2));
|
||||
var poolArray = ArrayPool.Rent(Math.Max(_length + additionalCapacityBeyondPos, _chars.Length * 2));
|
||||
|
||||
_chars[.._length].CopyTo(poolArray);
|
||||
|
||||
char[] toReturn = _arrayToReturnToPool;
|
||||
var toReturn = _arrayToReturnToPool;
|
||||
_chars = _arrayToReturnToPool = poolArray;
|
||||
if (toReturn != null)
|
||||
{
|
||||
|
|
@ -372,7 +372,7 @@ public ref struct ValueStringBuilder
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ReplaceAny(ReadOnlySpan<char> oldChars, ReadOnlySpan<char> newChars, int startIndex, int count)
|
||||
{
|
||||
int currentLength = _length;
|
||||
var currentLength = _length;
|
||||
if ((uint)startIndex > (uint)currentLength)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(startIndex));
|
||||
|
|
@ -403,7 +403,7 @@ public ref struct ValueStringBuilder
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Replace(char oldChar, char newChar, int startIndex, int count)
|
||||
{
|
||||
int currentLength = _length;
|
||||
var currentLength = _length;
|
||||
if ((uint)startIndex > (uint)currentLength)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(startIndex));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue