-
-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1901 from SixLabors/af/faster-getrowspan
Speed up DangerousGetRowSpan(y)
- Loading branch information
Showing
18 changed files
with
462 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupSpanCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using System; | ||
using System.Buffers; | ||
using SixLabors.ImageSharp.Memory.Internals; | ||
|
||
namespace SixLabors.ImageSharp.Memory | ||
{ | ||
/// <summary> | ||
/// Cached pointer or array data enabling fast <see cref="Span{T}"/> access from | ||
/// known <see cref="IMemoryOwner{T}"/> implementations. | ||
/// </summary> | ||
internal unsafe struct MemoryGroupSpanCache | ||
{ | ||
public SpanCacheMode Mode; | ||
public byte[] SingleArray; | ||
public void* SinglePointer; | ||
public void*[] MultiPointer; | ||
|
||
public static MemoryGroupSpanCache Create<T>(IMemoryOwner<T>[] memoryOwners) | ||
where T : struct | ||
{ | ||
IMemoryOwner<T> owner0 = memoryOwners[0]; | ||
MemoryGroupSpanCache memoryGroupSpanCache = default; | ||
if (memoryOwners.Length == 1) | ||
{ | ||
if (owner0 is SharedArrayPoolBuffer<T> sharedPoolBuffer) | ||
{ | ||
memoryGroupSpanCache.Mode = SpanCacheMode.SingleArray; | ||
memoryGroupSpanCache.SingleArray = sharedPoolBuffer.Array; | ||
} | ||
else if (owner0 is UnmanagedBuffer<T> unmanagedBuffer) | ||
{ | ||
memoryGroupSpanCache.Mode = SpanCacheMode.SinglePointer; | ||
memoryGroupSpanCache.SinglePointer = unmanagedBuffer.Pointer; | ||
} | ||
} | ||
else if (owner0 is UnmanagedBuffer<T>) | ||
{ | ||
memoryGroupSpanCache.Mode = SpanCacheMode.MultiPointer; | ||
memoryGroupSpanCache.MultiPointer = new void*[memoryOwners.Length]; | ||
for (int i = 0; i < memoryOwners.Length; i++) | ||
{ | ||
memoryGroupSpanCache.MultiPointer[i] = ((UnmanagedBuffer<T>)memoryOwners[i]).Pointer; | ||
} | ||
} | ||
|
||
return memoryGroupSpanCache; | ||
} | ||
} | ||
} |
Oops, something went wrong.