Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void AppendFormatted<T>(T value)
// if it only implements IFormattable, we come out even: only if it implements both do we
// end up paying for an extra interface check.
string? s;
if (value is IFormattable)
if (value is IFormattable formattable)
{
// If the value can format itself directly into our buffer, do so.

Expand All @@ -271,10 +271,10 @@ public void AppendFormatted<T>(T value)
return;
}

if (value is ISpanFormattable)
if (value is ISpanFormattable spanFormattable)
{
int charsWritten;
while (!((ISpanFormattable)value).TryFormat(_chars.Slice(_pos), out charsWritten, default, _provider)) // constrained call avoiding boxing for value types
while (!spanFormattable.TryFormat(_chars.Slice(_pos), out charsWritten, default, _provider)) // constrained call avoiding boxing for value types
{
Grow();
}
Expand All @@ -283,7 +283,7 @@ public void AppendFormatted<T>(T value)
return;
}

s = ((IFormattable)value).ToString(format: null, _provider); // constrained call avoiding boxing for value types
s = formattable.ToString(format: null, _provider); // constrained call avoiding boxing for value types
}
else
{
Expand Down Expand Up @@ -317,7 +317,7 @@ public void AppendFormatted<T>(T value, string? format)
// if it only implements IFormattable, we come out even: only if it implements both do we
// end up paying for an extra interface check.
string? s;
if (value is IFormattable)
if (value is IFormattable formattable)
{
// If the value can format itself directly into our buffer, do so.

Expand All @@ -333,10 +333,10 @@ public void AppendFormatted<T>(T value, string? format)
return;
}

if (value is ISpanFormattable)
if (value is ISpanFormattable spanFormattable)
{
int charsWritten;
while (!((ISpanFormattable)value).TryFormat(_chars.Slice(_pos), out charsWritten, format, _provider)) // constrained call avoiding boxing for value types
while (!spanFormattable.TryFormat(_chars.Slice(_pos), out charsWritten, format, _provider)) // constrained call avoiding boxing for value types
{
Grow();
}
Expand All @@ -345,7 +345,7 @@ public void AppendFormatted<T>(T value, string? format)
return;
}

s = ((IFormattable)value).ToString(format, _provider); // constrained call avoiding boxing for value types
s = formattable.ToString(format, _provider); // constrained call avoiding boxing for value types
}
else
{
Expand Down
Loading