resharper-heapview icon indicating copy to clipboard operation
resharper-heapview copied to clipboard

Incorrect boxing highlight for string concatenation and modern compilers

Open citizenmatt opened this issue 4 years ago • 2 comments

The code var x = "Hello " + longValue will show a highlight for boxing of the longValue variable. It appears previous compilers would box the value and call String.Concat(object, object). Modern compilers will call longValue.ToString() and then call String.Concat(string, string)

citizenmatt avatar Jun 25 '20 14:06 citizenmatt

myPrimitive.ToString() will still allocate a string object, if it hasn't been interned, right? In any case, if modern compilers skip the boxing then the plugin's message at least is incorrect.

neonb avatar Jan 05 '21 11:01 neonb

Partially fixed, boxing is not reported now. Will report implicit .ToString() invocation

controlflow avatar Jul 07 '22 13:07 controlflow

Both allocations are now reported: image image

Boxing is eliminated, but implicit .ToString() call still allocates a new string (at least for BCL's numeric types)

controlflow avatar Dec 28 '22 19:12 controlflow