From a45f49517b7fb4ed7981becb58898ea175273e80 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 23 Nov 2021 15:59:59 +0100 Subject: [PATCH] Avoid bounds checks in VectorMismatch --- src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs index 471c083cd..d24431600 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs @@ -81,7 +81,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless { int matchLen = 0; - while (matchLen < length && array1[matchLen] == array2[matchLen]) + ref uint array1Ref = ref MemoryMarshal.GetReference(array1); + ref uint array2Ref = ref MemoryMarshal.GetReference(array2); + while (matchLen < length && Unsafe.Add(ref array1Ref, matchLen) == Unsafe.Add(ref array2Ref, matchLen)) { matchLen++; }