Skip to content

Nullify the buffer in when calling ToStringAndClear#566

Merged
Iliya-usov merged 1 commit intoJetBrains:masterfrom
kevingosse:interpolated_string
Oct 27, 2025
Merged

Nullify the buffer in when calling ToStringAndClear#566
Iliya-usov merged 1 commit intoJetBrains:masterfrom
kevingosse:interpolated_string

Conversation

@kevingosse
Copy link
Contributor

In JetDefaultInterpolatedStringHandler, set the buffer to null instead of clearing it when ToStringAndClear is called.

On .NET Framework, if the StringBuilder has multiple chunks, calling Clear actually allocates a new chunk. An interpolated string handler isn't meant to be reused anyway ("The method should be invoked only once and as the last thing performed on the handler. Subsequent use is erroneous, ill-defined, and may destabilize the process"), so I believe it's better to just set the buffer to null.

The extra allocation when shrinking the StringBuilder has been removed in .NET Core 2.1, so we could in theory try to keep the call to Clear when running on .NET Core. However we don't have a netcore target (only netstandard, which can be used in a .net framework application), so I don't think it's worth the trouble.

@ForNeVeR ForNeVeR requested a review from Iliya-usov October 23, 2025 20:51
@Iliya-usov Iliya-usov merged commit e5b1092 into JetBrains:master Oct 27, 2025
9 checks passed
@kevingosse kevingosse deleted the interpolated_string branch October 30, 2025 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants