Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 519 Bytes

File metadata and controls

29 lines (20 loc) · 519 Bytes

Pattern: Use of Span<T>.Fill() instead of Span<T>.Clear()

Issue: -

Description

It's more efficient to call Span<T>.Clear() than to call Span<T>.Fill(T) to fill the elements of the span with a default value.

Example of incorrect code:

void M(Span<byte> span)
{
    span.Fill(0);
}

Example of correct code:

void M(Span<byte> span)
{
    span.Clear();
}

Further Reading