-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding span overloads for most of the interop extensions (#136)
- Loading branch information
1 parent
0acab90
commit 1017748
Showing
13 changed files
with
727 additions
and
345 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft and Contributors. All rights reserved. Licensed under the University of Illinois/NCSA Open Source License. See LICENSE.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Buffers; | ||
|
||
namespace LLVMSharp | ||
{ | ||
internal unsafe struct MarshaledArray<T, U> : IDisposable | ||
{ | ||
public MarshaledArray(ReadOnlySpan<T> inputs, Func<T, U> marshal) | ||
{ | ||
if (inputs.IsEmpty) | ||
{ | ||
Count = 0; | ||
Values = null; | ||
} | ||
else | ||
{ | ||
Count = inputs.Length; | ||
Values = ArrayPool<U>.Shared.Rent(Count); | ||
|
||
for (int i = 0; i < Count; i++) | ||
{ | ||
Values[i] = marshal(inputs[i]); | ||
} | ||
} | ||
} | ||
|
||
public int Count { get; private set; } | ||
|
||
public U[] Values { get; private set; } | ||
|
||
public static implicit operator ReadOnlySpan<U>(in MarshaledArray<T, U> value) | ||
{ | ||
return value.Values; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (Values != null) | ||
{ | ||
ArrayPool<U>.Shared.Return(Values); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.