Use const internally in corelib for Environment.NewLine#27013
Use const internally in corelib for Environment.NewLine#27013stephentoub merged 1 commit intodotnet:masterfrom
Conversation
|
Shouldn't UPD: ah, I guess JIT is not able to concat const strings yet (but would be nice to be able to fold CNS_STR nodes, I think it's not difficult to implement: #26000 (comment)) |
It of course could be done, but it'd be more than just handling constant strings... the JIT would need to unwind decisions the C# compiler makes about what overloads of string.Concat to use. |
I mean at least simple cases, e.g. (from your changes): text.Append(Environment.NewLine + InnerExceptionPrefix);So JIT in runtime should replace then is converted into: then JIT should fold it into just |
Anywhere Environment.NewLine was being used internal to corelib, instead changes it to use an internal Environment.NewLineConst, which is just a const string. The main benefit of that is places where it's then concatenated with another const allows the C# compiler to do the concat at compile time rather than at run time.
Where I was already touching the code, fixed a few places where additional strings were being created unnecessarily, e.g.
s += a; s += b;will do twostring.Concatcalls each with two arguments, whereass += a + b;will do just onestring.Concatcall with three arguments.