Make all interpolated string handlers pass by ref (#57536)
authorStephen Toub <stoub@microsoft.com>
Tue, 17 Aug 2021 18:17:14 +0000 (14:17 -0400)
committerGitHub <noreply@github.com>
Tue, 17 Aug 2021 18:17:14 +0000 (14:17 -0400)
commit80c7acc9dbfb1ad6021ca0ee2a3ca5adb46bf467
treeab9a0a59e98293ef0531bcc168ebf48ac4576a72
parent00e831d4ec5bf9c86e0d01b3b18b8d7246d6f74a
Make all interpolated string handlers pass by ref (#57536)

We currently pass all of our interpolated string handlers to their destination methods by ref, with the exception of those for Debug.  I think it makes sense to centralize on the pattern of always passing by ref: it doesn’t negatively impact the user experience, these are typically larger structs and so by ref helps (though it doesn’t matter for Debug), making it a ref makes it even less attractive to try to call directly / makes it look even more special, and most importantly, it gives us the opportunity to more safely clean up at the end of the operation.  This changes the Debug.Assert/Write{Line}If overloads we added in Preview 7 to pass the handler’s by ref.

This also then updates the Debug.Write{Line}If methods to create the StringBuilder used via StringBuilderCache, just in case these are used in a scenario where true is frequently passed.
src/libraries/System.Diagnostics.Debug/tests/DebugTestsNoListeners.Interpolation.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Debug.cs
src/libraries/System.Runtime/ref/System.Runtime.cs