Skip to content

Commit 0e8a2db

Browse files
committed
Added comments to DangerousGetReference tests
1 parent b75f238 commit 0e8a2db

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

UnitTests/UnitTests.HighPerformance.Shared/Extensions/Test_ArrayExtensions.1D.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public void Test_ArrayExtensions_DangerousGetReference()
1717
{
1818
string[] tokens = "aa,bb,cc,dd,ee,ff,gg,hh,ii".Split(',');
1919

20+
// In all these "DangerousGetReference" tests, we need to ensure that a reference to a given
21+
// item within an array is effectively the one corresponding to the one whe expect, which is
22+
// either a reference to the first item if we use "DangerousGetReference", or one to the n-th
23+
// item if we use "DangerousGetReferenceAt". So all these tests just invoke the API and then
24+
// compare the returned reference against an existing baseline (like the built-in array indexer)
25+
// to ensure that the two are the same. These are all managed references, so no need for pinning.
2026
ref string r0 = ref Unsafe.AsRef(tokens.DangerousGetReference());
2127
ref string r1 = ref Unsafe.AsRef(tokens[0]);
2228

UnitTests/UnitTests.HighPerformance.Shared/Extensions/Test_ArrayExtensions.2D.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void Test_ArrayExtensions_2D_DangerousGetReference_Int()
2424
{ 9, 10, 11, 12 }
2525
};
2626

27+
// See comments in Test_ArrayExtensions.1D for how these tests work
2728
ref int r0 = ref array.DangerousGetReference();
2829
ref int r1 = ref array[0, 0];
2930

UnitTests/UnitTests.HighPerformance.Shared/Extensions/Test_ArrayExtensions.3D.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public void Test_ArrayExtensions_3D_DangerousGetReference_Int()
1616
{
1717
int[,,] array = new int[10, 20, 12];
1818

19+
// See comments in Test_ArrayExtensions.1D for how these tests work
1920
ref int r0 = ref array.DangerousGetReference();
2021
ref int r1 = ref array[0, 0, 0];
2122

0 commit comments

Comments
 (0)