Skip to content

Commit

Permalink
Don't have struct local in ValueStringBuilder due to hitting JIT opti…
Browse files Browse the repository at this point in the history
…mization limits

Cf. #67448 (comment)
  • Loading branch information
gfoidl committed Apr 4, 2022
1 parent 20842e6 commit da31c0b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/libraries/Common/src/System/Text/ValueStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,9 @@ public void Insert(int index, string? s)
public void Append(char c)
{
int pos = _pos;
Span<char> chars = _chars;
if ((uint)pos < (uint)chars.Length)
if ((uint)pos < (uint)_chars.Length)
{
chars[pos] = c;
_chars[pos] = c;
_pos = pos + 1;
}
else
Expand All @@ -191,10 +190,9 @@ public void Append(string? s)
}

int pos = _pos;
Span<char> chars = _chars;
if (s.Length == 1 && (uint)pos < (uint)chars.Length) // very common case, e.g. appending strings from NumberFormatInfo like separators, percent symbols, etc.
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];
_chars[pos] = s[0];
_pos = pos + 1;
}
else
Expand Down

0 comments on commit da31c0b

Please sign in to comment.