Skip to content

Commit 38eb7fc

Browse files
committed
Big ol' cleanup
1 parent b9bba1d commit 38eb7fc

12 files changed

+107
-106
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Native Array Span Extensions
22

33
[![License](https://img.shields.io/github/license/Voltstro-Studios/NativeArraySpanExtensions.svg)](/LICENSE.md)
4-
[![Discord](https://img.shields.io/badge/Discord-Voltstro-7289da.svg?logo=discord)](https://discord.voltstro.dev)
4+
[![Discord](https://img.shields.io/badge/Discord-Voltstro-7289da.svg?logo=discord)](https://discord.voltstro.dev)
55
[![YouTube](https://img.shields.io/badge/Youtube-Voltstro-red.svg?logo=youtube)](https://www.youtube.com/Voltstro)
66

77
Provides extensions to Unity's `NativeArray<T>` that make using .NET's Span<T> with them easier.
@@ -34,7 +34,8 @@ There are three main sources on how you can install this package. Pick which eve
3434

3535
#### Voltstro UPM Registry
3636

37-
You can install this package from our custom UPM registry. To setup our registry, see [here](https://github.com/Voltstro/VoltstroUPM#setup).
37+
You can install this package from our custom UPM registry. To setup our registry,
38+
see [here](https://github.com/Voltstro/VoltstroUPM#setup).
3839

3940
Once you have the registry added to your project, you can install it like any other package via the package manager.
4041

@@ -45,7 +46,7 @@ You can install this package via [OpenUPM](https://openupm.com/).
4546
To install it, use their CLI:
4647

4748
```bash
48-
openupm-cli add dev.voltstro.nativearrayspanextensions
49+
openupm add dev.voltstro.nativearrayspanextensions
4950
```
5051

5152
#### Git

Runtime/NativeArrayExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
namespace VoltstroStudios.NativeArraySpanExtensions
66
{
77
/// <summary>
8-
/// Provides <see cref="Span{T}"/> copying utils to <see cref="NativeArray{T}"/>
8+
/// Provides <see cref="Span{T}" /> copying utils to <see cref="NativeArray{T}" />
99
/// </summary>
1010
public static class NativeArrayExtensions
1111
{
1212
/// <summary>
13-
/// Copy data from a <see cref="ReadOnlySpan{T}"/> to a <see cref="NativeArray{T}"/>
13+
/// Copy data from a <see cref="ReadOnlySpan{T}" /> to a <see cref="NativeArray{T}" />
1414
/// </summary>
1515
/// <param name="array"></param>
1616
/// <param name="source"></param>
@@ -19,7 +19,7 @@ public static unsafe void CopyFrom<T>(this NativeArray<T> array, ReadOnlySpan<T>
1919
where T : unmanaged
2020
{
2121
Utils.CheckCopyLengths(source.Length, array.Length);
22-
22+
2323
//Calling GetUnsafePtr will check if the array is valid for us
2424
//(if checks are enabled)
2525
void* dstPtr = array.GetUnsafePtr();
@@ -31,7 +31,7 @@ public static unsafe void CopyFrom<T>(this NativeArray<T> array, ReadOnlySpan<T>
3131
}
3232

3333
/// <summary>
34-
/// Copy data from a <see cref="NativeArray{T}"/> to a <see cref="Span{T}"/>
34+
/// Copy data from a <see cref="NativeArray{T}" /> to a <see cref="Span{T}" />
3535
/// </summary>
3636
/// <param name="array"></param>
3737
/// <param name="dst"></param>
@@ -51,4 +51,4 @@ public static unsafe void CopyTo<T>(this NativeArray<T> array, Span<T> dst)
5151
}
5252
}
5353
}
54-
}
54+
}

Runtime/NativeSliceExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
namespace VoltstroStudios.NativeArraySpanExtensions
66
{
77
/// <summary>
8-
/// Provides <see cref="Span{T}"/> copying utils to <see cref="NativeSlice{T}"/>
8+
/// Provides <see cref="Span{T}" /> copying utils to <see cref="NativeSlice{T}" />
99
/// </summary>
1010
public static class NativeSliceExtensions
1111
{
1212
/// <summary>
13-
/// Copy data from a <see cref="ReadOnlySpan{T}"/> to a <see cref="NativeSlice{T}"/>
13+
/// Copy data from a <see cref="ReadOnlySpan{T}" /> to a <see cref="NativeSlice{T}" />
1414
/// </summary>
1515
/// <param name="array"></param>
1616
/// <param name="source"></param>
@@ -29,9 +29,9 @@ public static unsafe void CopyFrom<T>(this NativeSlice<T> array, ReadOnlySpan<T>
2929
Utils.Copy<T>(srcPtr, 0, dstPtr, 0, array.Length);
3030
}
3131
}
32-
32+
3333
/// <summary>
34-
/// Copy data from a <see cref="NativeSlice{T}"/> to a <see cref="Span{T}"/>
34+
/// Copy data from a <see cref="NativeSlice{T}" /> to a <see cref="Span{T}" />
3535
/// </summary>
3636
/// <param name="array"></param>
3737
/// <param name="dst"></param>

Runtime/SpanExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
namespace VoltstroStudios.NativeArraySpanExtensions
55
{
66
/// <summary>
7-
/// Provides <see cref="NativeArray{T}"/> copying utils to <see cref="Span{T}"/>
7+
/// Provides <see cref="NativeArray{T}" /> copying utils to <see cref="Span{T}" />
88
/// </summary>
99
public static class SpanExtensions
1010
{
1111
/// <summary>
12-
/// Copy data from a <see cref="Span{T}"/> to a <see cref="NativeArray{T}"/>
12+
/// Copy data from a <see cref="Span{T}" /> to a <see cref="NativeArray{T}" />
1313
/// </summary>
1414
/// <param name="source"></param>
1515
/// <param name="dst"></param>
1616
/// <typeparam name="T"></typeparam>
1717
public static void CopyTo<T>(this Span<T> source, NativeArray<T> dst)
1818
where T : unmanaged
1919
{
20-
CopyTo((ReadOnlySpan<T>) source, dst);
20+
CopyTo((ReadOnlySpan<T>)source, dst);
2121
}
22-
22+
2323
/// <summary>
24-
/// Copy data from a <see cref="ReadOnlySpan{T}"/> to a <see cref="NativeArray{T}"/>
24+
/// Copy data from a <see cref="ReadOnlySpan{T}" /> to a <see cref="NativeArray{T}" />
2525
/// </summary>
2626
/// <param name="source"></param>
2727
/// <param name="dst"></param>
@@ -33,7 +33,7 @@ public static void CopyTo<T>(this ReadOnlySpan<T> source, NativeArray<T> dst)
3333
}
3434

3535
/// <summary>
36-
/// Creates a <see cref="NativeArray{T}"/> from a <see cref="Span{T}"/>
36+
/// Creates a <see cref="NativeArray{T}" /> from a <see cref="Span{T}" />
3737
/// </summary>
3838
/// <param name="source"></param>
3939
/// <param name="allocator"></param>
@@ -46,7 +46,7 @@ public static NativeArray<T> ToNativeArray<T>(this Span<T> source, Allocator all
4646
}
4747

4848
/// <summary>
49-
/// Creates a <see cref="NativeArray{T}"/> from a <see cref="ReadOnlySpan{T}"/>
49+
/// Creates a <see cref="NativeArray{T}" /> from a <see cref="ReadOnlySpan{T}" />
5050
/// </summary>
5151
/// <param name="source"></param>
5252
/// <param name="allocator"></param>
@@ -60,4 +60,4 @@ public static NativeArray<T> ToNativeArray<T>(this ReadOnlySpan<T> source, Alloc
6060
return newArray;
6161
}
6262
}
63-
}
63+
}

Runtime/Utils.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ internal static unsafe void Copy<T>(void* src, int srcIndex,
1111
int length)
1212
where T : unmanaged
1313
{
14-
UnsafeUtility.MemCpy((void*) ((IntPtr) dst + dstIndex * UnsafeUtility.SizeOf<T>()),
15-
(void*) ((IntPtr) src + srcIndex * UnsafeUtility.SizeOf<T>()),
16-
(long) (length * UnsafeUtility.SizeOf<T>()));
14+
UnsafeUtility.MemCpy((void*)((IntPtr)dst + dstIndex * UnsafeUtility.SizeOf<T>()),
15+
(void*)((IntPtr)src + srcIndex * UnsafeUtility.SizeOf<T>()),
16+
length * UnsafeUtility.SizeOf<T>());
1717
}
1818

1919
[Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
@@ -23,4 +23,4 @@ internal static void CheckCopyLengths(int srcLength, int dstLength)
2323
throw new ArgumentException("source and destination length must be the same");
2424
}
2525
}
26-
}
26+
}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"name": "VoltstroStudios.NativeArraySpanExtensions",
3-
"rootNamespace": "VoltstroStudios.NativeArraySpanExtensions",
4-
"references": [],
5-
"includePlatforms": [],
6-
"excludePlatforms": [],
7-
"allowUnsafeCode": true,
8-
"overrideReferences": false,
9-
"precompiledReferences": [],
10-
"autoReferenced": true,
11-
"defineConstraints": [],
12-
"versionDefines": [],
13-
"noEngineReferences": false
2+
"name": "VoltstroStudios.NativeArraySpanExtensions",
3+
"rootNamespace": "VoltstroStudios.NativeArraySpanExtensions",
4+
"references": [],
5+
"includePlatforms": [],
6+
"excludePlatforms": [],
7+
"allowUnsafeCode": true,
8+
"overrideReferences": false,
9+
"precompiledReferences": [],
10+
"autoReferenced": true,
11+
"defineConstraints": [],
12+
"versionDefines": [],
13+
"noEngineReferences": false
1414
}

Tests/Runtime/GenericTestCaseAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace VoltstroStudios.NativeArraySpanExtensions.Tests
1111
public class GenericTestCaseAttribute : TestCaseAttribute, ITestBuilder
1212
{
1313
private readonly Type type;
14+
1415
public GenericTestCaseAttribute(Type type, params object[] arguments) : base(arguments)
1516
{
1617
this.type = type;
@@ -23,6 +24,7 @@ IEnumerable<TestMethod> ITestBuilder.BuildFrom(IMethodInfo method, Test suite)
2324
IMethodInfo gm = method.MakeGenericMethod(type);
2425
return BuildFrom(gm, suite);
2526
}
27+
2628
return BuildFrom(method, suite);
2729
}
2830
}

Tests/Runtime/NativeArrayExtensionsTests.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,32 @@ namespace VoltstroStudios.NativeArraySpanExtensions.Tests
66
{
77
public class NativeArrayExtensionsTests
88
{
9-
[GenericTestCase(typeof(byte), new byte[]{1, 4, 6, 7, 54, 98})]
10-
[GenericTestCase(typeof(int), new[]{54, 76, 129, 7000, 438, 57, 192, 69})]
11-
[GenericTestCase(typeof(float), new[]{0.0002456f, 69.420f, 23f, 90032.2f, 47.6f})]
9+
[GenericTestCase(typeof(byte), new byte[] { 1, 4, 6, 7, 54, 98 })]
10+
[GenericTestCase(typeof(int), new[] { 54, 76, 129, 7000, 438, 57, 192, 69 })]
11+
[GenericTestCase(typeof(float), new[] { 0.0002456f, 69.420f, 23f, 90032.2f, 47.6f })]
1212
public void CopyFromTest<T>(T[] testData)
1313
where T : unmanaged
1414
{
15-
NativeArray<T> testNativeArray = new(testData.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
15+
NativeArray<T> testNativeArray =
16+
new(testData.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
1617
try
1718
{
1819
Assert.IsTrue(testNativeArray.IsCreated);
1920

2021
Span<T> testSpan = testData;
2122
testNativeArray.CopyFrom(testSpan);
22-
23+
2324
TestUtils.ValidateArrays(testNativeArray, testSpan);
2425
}
2526
finally
2627
{
2728
testNativeArray.Dispose();
2829
}
2930
}
30-
31-
[GenericTestCase(typeof(byte), new byte[]{1, 4, 6, 7, 54, 98})]
32-
[GenericTestCase(typeof(int), new[]{54, 76, 129, 7000, 438, 57, 192, 69})]
33-
[GenericTestCase(typeof(float), new[]{0.0002456f, 69.420f, 23f, 90032.2f, 47.6f})]
31+
32+
[GenericTestCase(typeof(byte), new byte[] { 1, 4, 6, 7, 54, 98 })]
33+
[GenericTestCase(typeof(int), new[] { 54, 76, 129, 7000, 438, 57, 192, 69 })]
34+
[GenericTestCase(typeof(float), new[] { 0.0002456f, 69.420f, 23f, 90032.2f, 47.6f })]
3435
public void CopyTo<T>(T[] testData)
3536
where T : unmanaged
3637
{
@@ -50,4 +51,4 @@ public void CopyTo<T>(T[] testData)
5051
}
5152
}
5253
}
53-
}
54+
}

Tests/Runtime/NativeSliceExtensionsTests.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ namespace VoltstroStudios.NativeArraySpanExtensions.Tests
66
{
77
public class NativeSliceExtensionsTests
88
{
9-
[GenericTestCase(typeof(byte), new byte[]{1, 4, 6, 7, 54, 98})]
10-
[GenericTestCase(typeof(int), new[]{54, 76, 129, 7000, 438, 57, 192, 69})]
11-
[GenericTestCase(typeof(float), new[]{0.0002456f, 69.420f, 23f, 90032.2f, 47.6f})]
9+
[GenericTestCase(typeof(byte), new byte[] { 1, 4, 6, 7, 54, 98 })]
10+
[GenericTestCase(typeof(int), new[] { 54, 76, 129, 7000, 438, 57, 192, 69 })]
11+
[GenericTestCase(typeof(float), new[] { 0.0002456f, 69.420f, 23f, 90032.2f, 47.6f })]
1212
public void CopyFromTest<T>(T[] testData)
1313
where T : unmanaged
1414
{
15-
NativeArray<T> testNativeArray = new(testData.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
15+
NativeArray<T> testNativeArray =
16+
new(testData.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
1617
NativeSlice<T> testNativeSlice = testNativeArray.Slice();
1718

1819
try
@@ -21,24 +22,24 @@ public void CopyFromTest<T>(T[] testData)
2122

2223
Span<T> testSpan = testData;
2324
testNativeSlice.CopyFrom(testSpan);
24-
25+
2526
ValidateArrays(testNativeSlice, testSpan);
2627
}
2728
finally
2829
{
2930
testNativeArray.Dispose();
3031
}
3132
}
32-
33-
[GenericTestCase(typeof(byte), new byte[]{1, 4, 6, 7, 54, 98})]
34-
[GenericTestCase(typeof(int), new[]{54, 76, 129, 7000, 438, 57, 192, 69})]
35-
[GenericTestCase(typeof(float), new[]{0.0002456f, 69.420f, 23f, 90032.2f, 47.6f})]
33+
34+
[GenericTestCase(typeof(byte), new byte[] { 1, 4, 6, 7, 54, 98 })]
35+
[GenericTestCase(typeof(int), new[] { 54, 76, 129, 7000, 438, 57, 192, 69 })]
36+
[GenericTestCase(typeof(float), new[] { 0.0002456f, 69.420f, 23f, 90032.2f, 47.6f })]
3637
public void CopyTo<T>(T[] testData)
3738
where T : unmanaged
3839
{
3940
NativeArray<T> testNativeArray = new(testData, Allocator.Temp);
4041
NativeSlice<T> testNativeSlice = testNativeArray.Slice();
41-
42+
4243
try
4344
{
4445
Assert.IsTrue(testNativeArray.IsCreated);
@@ -53,15 +54,12 @@ public void CopyTo<T>(T[] testData)
5354
testNativeArray.Dispose();
5455
}
5556
}
56-
57+
5758
private static void ValidateArrays<T>(NativeSlice<T> nativeArray, ReadOnlySpan<T> span)
5859
where T : unmanaged
5960
{
6061
Assert.AreEqual(nativeArray.Length, span.Length);
61-
for (int i = 0; i < nativeArray.Length; i++)
62-
{
63-
Assert.AreEqual(nativeArray[i], span[i]);
64-
}
62+
for (int i = 0; i < nativeArray.Length; i++) Assert.AreEqual(nativeArray[i], span[i]);
6563
}
6664
}
6765
}

0 commit comments

Comments
 (0)