Skip to content

Commit ad2632f

Browse files
committed
optimize RowOctet<T> indexer
1 parent b0646df commit ad2632f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
5+
using System.Runtime.CompilerServices;
56
using System.Runtime.InteropServices;
67
using SixLabors.ImageSharp.Memory;
78

@@ -39,6 +40,7 @@ public RowOctet(Buffer2D<T> buffer, int startY)
3940

4041
public Span<T> this[int y]
4142
{
43+
[MethodImpl(InliningOptions.ShortMethod)]
4244
get
4345
{
4446
// No unsafe tricks, since Span<T> can't be used as a generic argument
@@ -52,9 +54,15 @@ public Span<T> this[int y]
5254
5 => this.row5,
5355
6 => this.row6,
5456
7 => this.row7,
55-
_ => throw new IndexOutOfRangeException()
57+
_ => ThrowIndexOutOfRangeException()
5658
};
5759
}
5860
}
61+
62+
[MethodImpl(InliningOptions.ColdPath)]
63+
private static Span<T> ThrowIndexOutOfRangeException()
64+
{
65+
throw new IndexOutOfRangeException();
66+
}
5967
}
6068
}

0 commit comments

Comments
 (0)