Browse Source

use InliningOptions.ShortMethod

pull/768/head
Anton Firszov 7 years ago
parent
commit
bd4b78544f
  1. 30
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
  2. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs
  3. 4
      src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

30
src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs

@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <returns>The float value at the specified index</returns> /// <returns>The float value at the specified index</returns>
public float this[int idx] public float this[int idx]
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
get get
{ {
GuardBlockIndex(idx); GuardBlockIndex(idx);
@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
return Unsafe.Add(ref selfRef, idx); return Unsafe.Add(ref selfRef, idx);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
set set
{ {
GuardBlockIndex(idx); GuardBlockIndex(idx);
@ -149,7 +149,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <summary> /// <summary>
/// Fill the block with defaults (zeroes) /// Fill the block with defaults (zeroes)
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public void Clear() public void Clear()
{ {
// The cheapest way to do this in C#: // The cheapest way to do this in C#:
@ -160,7 +160,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Load raw 32bit floating point data from source /// Load raw 32bit floating point data from source
/// </summary> /// </summary>
/// <param name="source">Source</param> /// <param name="source">Source</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public void LoadFrom(Span<float> source) public void LoadFrom(Span<float> source)
{ {
ref byte s = ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(source)); ref byte s = ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(source));
@ -174,7 +174,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// </summary> /// </summary>
/// <param name="blockPtr">Block pointer</param> /// <param name="blockPtr">Block pointer</param>
/// <param name="source">Source</param> /// <param name="source">Source</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public static unsafe void LoadFrom(Block8x8F* blockPtr, Span<float> source) public static unsafe void LoadFrom(Block8x8F* blockPtr, Span<float> source)
{ {
blockPtr->LoadFrom(source); blockPtr->LoadFrom(source);
@ -200,7 +200,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Copy raw 32bit floating point data to dest /// Copy raw 32bit floating point data to dest
/// </summary> /// </summary>
/// <param name="dest">Destination</param> /// <param name="dest">Destination</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public void CopyTo(Span<float> dest) public void CopyTo(Span<float> dest)
{ {
ref byte d = ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(dest)); ref byte d = ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(dest));
@ -214,7 +214,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// </summary> /// </summary>
/// <param name="blockPtr">Pointer to block</param> /// <param name="blockPtr">Pointer to block</param>
/// <param name="dest">Destination</param> /// <param name="dest">Destination</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public static unsafe void CopyTo(Block8x8F* blockPtr, Span<byte> dest) public static unsafe void CopyTo(Block8x8F* blockPtr, Span<byte> dest)
{ {
float* fPtr = (float*)blockPtr; float* fPtr = (float*)blockPtr;
@ -230,7 +230,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// </summary> /// </summary>
/// <param name="blockPtr">Block pointer</param> /// <param name="blockPtr">Block pointer</param>
/// <param name="dest">Destination</param> /// <param name="dest">Destination</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public static unsafe void CopyTo(Block8x8F* blockPtr, Span<float> dest) public static unsafe void CopyTo(Block8x8F* blockPtr, Span<float> dest)
{ {
blockPtr->CopyTo(dest); blockPtr->CopyTo(dest);
@ -240,7 +240,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Copy raw 32bit floating point data to dest /// Copy raw 32bit floating point data to dest
/// </summary> /// </summary>
/// <param name="dest">Destination</param> /// <param name="dest">Destination</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public unsafe void CopyTo(float[] dest) public unsafe void CopyTo(float[] dest)
{ {
fixed (void* ptr = &this.V0L) fixed (void* ptr = &this.V0L)
@ -276,7 +276,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Multiply all elements of the block. /// Multiply all elements of the block.
/// </summary> /// </summary>
/// <param name="value">The value to multiply by</param> /// <param name="value">The value to multiply by</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public void MultiplyInplace(float value) public void MultiplyInplace(float value)
{ {
this.V0L *= value; this.V0L *= value;
@ -300,7 +300,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <summary> /// <summary>
/// Multiply all elements of the block by the corresponding elements of 'other' /// Multiply all elements of the block by the corresponding elements of 'other'
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public void MultiplyInplace(ref Block8x8F other) public void MultiplyInplace(ref Block8x8F other)
{ {
this.V0L *= other.V0L; this.V0L *= other.V0L;
@ -325,7 +325,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// Adds a vector to all elements of the block. /// Adds a vector to all elements of the block.
/// </summary> /// </summary>
/// <param name="diff">The added vector</param> /// <param name="diff">The added vector</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public void AddToAllInplace(Vector4 diff) public void AddToAllInplace(Vector4 diff)
{ {
this.V0L += diff; this.V0L += diff;
@ -420,7 +420,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
} }
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
private static void DivideRoundAll(ref Block8x8F a, ref Block8x8F b) private static void DivideRoundAll(ref Block8x8F a, ref Block8x8F b)
{ {
a.V0L = DivideRound(a.V0L, b.V0L); a.V0L = DivideRound(a.V0L, b.V0L);
@ -511,7 +511,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
return sb.ToString(); return sb.ToString();
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
private static Vector<float> NormalizeAndRound(Vector<float> row, Vector<float> off, Vector<float> max) private static Vector<float> NormalizeAndRound(Vector<float> row, Vector<float> off, Vector<float> max)
{ {
row += off; row += off;
@ -520,7 +520,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
return row.FastRound(); return row.FastRound();
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
private static Vector4 DivideRound(Vector4 dividend, Vector4 divisor) private static Vector4 DivideRound(Vector4 dividend, Vector4 divisor)
{ {
// sign(dividend) = max(min(dividend, 1), -1) // sign(dividend) = max(min(dividend, 1), -1)

2
src/ImageSharp/Formats/Jpeg/Components/Decoder/ScanDecoder.cs

@ -142,7 +142,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
} }
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
private static uint LRot(uint x, int y) => (x << y) | (x >> (32 - y)); private static uint LRot(uint x, int y) => (x << y) | (x >> (32 - y));
private void ParseBaselineData() private void ParseBaselineData()

4
src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs

@ -913,7 +913,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <param name="index">The table index</param> /// <param name="index">The table index</param>
/// <param name="codeLengths">The codelengths</param> /// <param name="codeLengths">The codelengths</param>
/// <param name="values">The values</param> /// <param name="values">The values</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
private void BuildHuffmanTable(HuffmanTables tables, int index, ReadOnlySpan<byte> codeLengths, ReadOnlySpan<byte> values) private void BuildHuffmanTable(HuffmanTables tables, int index, ReadOnlySpan<byte> codeLengths, ReadOnlySpan<byte> values)
=> tables[index] = new HuffmanTable(this.configuration.MemoryAllocator, codeLengths, values); => tables[index] = new HuffmanTable(this.configuration.MemoryAllocator, codeLengths, values);
@ -921,7 +921,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// Reads a <see cref="ushort"/> from the stream advancing it by two bytes /// Reads a <see cref="ushort"/> from the stream advancing it by two bytes
/// </summary> /// </summary>
/// <returns>The <see cref="ushort"/></returns> /// <returns>The <see cref="ushort"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
private ushort ReadUint16() private ushort ReadUint16()
{ {
this.InputStream.Read(this.markerBuffer, 0, 2); this.InputStream.Read(this.markerBuffer, 0, 2);

Loading…
Cancel
Save