Skip to content

Commit 49d86e1

Browse files
committed
Use buffer as span to reduce some bound checks when writing components
1 parent f39702f commit 49d86e1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,10 @@ private void WriteStartOfFrame(int width, int height, int componentCount, ReadOn
642642
int i3 = 3 * i;
643643

644644
// Component ID.
645-
this.buffer[i3 + 6] = componentIds[i];
646-
this.buffer[i3 + 7] = subsamples[i];
647-
this.buffer[i3 + 8] = chroma[i];
645+
Span<byte> bufferSpan = this.buffer.AsSpan(i3 + 6, 3);
646+
bufferSpan[2] = chroma[i];
647+
bufferSpan[1] = subsamples[i];
648+
bufferSpan[0] = componentIds[i];
648649
}
649650

650651
this.outputStream.Write(this.buffer, 0, (3 * (componentCount - 1)) + 9);

0 commit comments

Comments
 (0)