-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add InlineArrayX types #113403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add InlineArrayX types #113403
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
145 changes: 145 additions & 0 deletions
145
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/InlineArray.cs
This file contains hidden or 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,145 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Runtime.CompilerServices | ||
| { | ||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 2. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(2)] | ||
| public struct InlineArray2<T> | ||
| { | ||
| private T t; | ||
333fred marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
333fred marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 3. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(3)] | ||
| public struct InlineArray3<T> | ||
| { | ||
| private T t; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 4. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(4)] | ||
| public struct InlineArray4<T> | ||
| { | ||
| private T t; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 5. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(5)] | ||
| public struct InlineArray5<T> | ||
| { | ||
| private T t; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 6. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(6)] | ||
| public struct InlineArray6<T> | ||
| { | ||
| private T t; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 7. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(7)] | ||
| public struct InlineArray7<T> | ||
| { | ||
| private T t; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 8. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(8)] | ||
| public struct InlineArray8<T> | ||
| { | ||
| private T t; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 9. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(9)] | ||
| public struct InlineArray9<T> | ||
| { | ||
| private T t; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 10. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(10)] | ||
| public struct InlineArray10<T> | ||
| { | ||
| private T t; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 11. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(11)] | ||
| public struct InlineArray11<T> | ||
| { | ||
| private T t; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 12. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(12)] | ||
| public struct InlineArray12<T> | ||
| { | ||
| private T t; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 13. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(13)] | ||
| public struct InlineArray13<T> | ||
| { | ||
| private T t; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 14. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(14)] | ||
| public struct InlineArray14<T> | ||
| { | ||
| private T t; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents an inline array of <typeparamref name="T"/> with a fixed length of 15. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the array.</typeparam> | ||
| [InlineArray(15)] | ||
| public struct InlineArray15<T> | ||
| { | ||
| private T t; | ||
| } | ||
| } | ||
This file contains hidden or 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
124 changes: 124 additions & 0 deletions
124
...em.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/InlineArrayTests.cs
This file contains hidden or 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,124 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Reflection; | ||
| using Xunit; | ||
|
|
||
| namespace System.Runtime.CompilerServices.Tests | ||
| { | ||
| public static class InlineArrayTests | ||
| { | ||
| private static void WriteRead(Span<int> span, int expectedLength) | ||
| { | ||
| Assert.Equal(expectedLength, span.Length); | ||
|
|
||
| for (int i = 0; i < span.Length; i++) | ||
| { | ||
| span[i] = i + 1; | ||
| } | ||
|
|
||
| for (int i = 0; i < span.Length; i++) | ||
| { | ||
| Assert.Equal(i + 1, span[i]); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray2Test() | ||
| { | ||
| InlineArray2<int> inlineArray2 = new(); | ||
| WriteRead(inlineArray2, 2); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray3Test() | ||
| { | ||
| InlineArray3<int> inlineArray3 = new(); | ||
| WriteRead(inlineArray3, 3); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray4Test() | ||
| { | ||
| InlineArray4<int> inlineArray4 = new(); | ||
| WriteRead(inlineArray4, 4); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray5Test() | ||
| { | ||
| InlineArray5<int> inlineArray5 = new(); | ||
| WriteRead(inlineArray5, 5); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray6Test() | ||
| { | ||
| InlineArray6<int> inlineArray6 = new(); | ||
| WriteRead(inlineArray6, 6); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray7Test() | ||
| { | ||
| InlineArray7<int> inlineArray7 = new(); | ||
| WriteRead(inlineArray7, 7); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray8Test() | ||
| { | ||
| InlineArray8<int> inlineArray8 = new(); | ||
| WriteRead(inlineArray8, 8); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray9Test() | ||
| { | ||
| InlineArray9<int> inlineArray9 = new(); | ||
| WriteRead(inlineArray9, 9); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray10Test() | ||
| { | ||
| InlineArray10<int> inlineArray10 = new(); | ||
| WriteRead(inlineArray10, 10); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray11Test() | ||
| { | ||
| InlineArray11<int> inlineArray11 = new(); | ||
| WriteRead(inlineArray11, 11); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray12Test() | ||
| { | ||
| InlineArray12<int> inlineArray12 = new(); | ||
| WriteRead(inlineArray12, 12); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray13Test() | ||
| { | ||
| InlineArray13<int> inlineArray13 = new(); | ||
| WriteRead(inlineArray13, 13); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray14Test() | ||
| { | ||
| InlineArray14<int> inlineArray14 = new(); | ||
| WriteRead(inlineArray14, 14); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InlineArray15Test() | ||
| { | ||
| InlineArray15<int> inlineArray15 = new(); | ||
| WriteRead(inlineArray15, 15); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.