Open
Description
Background and motivation
Given copy unrolling improvements, using span.CopyTo(dest)
should outperform manual copy with a loop in almost every situation. It may be desirable to have a performance analyzer rule to flag such use cases and suggest an auto-fixer to address them.
Example pattern spotted in
runtime/src/libraries/System.Private.CoreLib/src/System/IO/StreamWriter.cs
Lines 405 to 413 in 2ab51c6
API Usage
var src = Enumerable
.Range(0, 16)
.Select(num => num.ToString())
.ToArray()
.AsSpan()
var dst = new string[16];
// Flagged with a rule "use span.CopyTo for copying elements"
for (var i = 0; i < src.Length; i++)
{
dst[i] = src[i];
}
Alternative Designs
N/A
Risks
Should be none (right? :) )