From cb716af1cc859e45ce4b14266657d91d7b6389f1 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 21 Feb 2020 12:11:35 +0100 Subject: [PATCH] optimize RowOctet indexer --- src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs b/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs index 57a134703..8c3daa4d5 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SixLabors.ImageSharp.Memory; @@ -39,6 +40,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components public Span this[int y] { + [MethodImpl(InliningOptions.ShortMethod)] get { // No unsafe tricks, since Span can't be used as a generic argument @@ -52,9 +54,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components 5 => this.row5, 6 => this.row6, 7 => this.row7, - _ => throw new IndexOutOfRangeException() + _ => ThrowIndexOutOfRangeException() }; } } + + [MethodImpl(InliningOptions.ColdPath)] + private static Span ThrowIndexOutOfRangeException() + { + throw new IndexOutOfRangeException(); + } } }