-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Poly fill Index and Range types #104170
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
Poly fill Index and Range types #104170
Changes from all commits
Commits
Show all changes
3 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
43 changes: 43 additions & 0 deletions
43
src/libraries/Common/tests/System/Runtime/CompilerServices/RuntimeHelpers.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,43 @@ | ||
| // 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 | ||
| { | ||
| internal static class RuntimeHelpers | ||
| { | ||
| /// <summary> | ||
| /// Slices the specified array using the specified range. | ||
| /// </summary> | ||
| internal static T[] GetSubArray<T>(T[] array, Range range) | ||
| { | ||
| if (array == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(array)); | ||
| } | ||
|
|
||
| (int offset, int length) = range.GetOffsetAndLength(array.Length); | ||
|
|
||
| if (default(T) != null || typeof(T[]) == array.GetType()) | ||
| { | ||
| // We know the type of the array to be exactly T[]. | ||
|
|
||
| if (length == 0) | ||
| { | ||
| return Array.Empty<T>(); | ||
| } | ||
|
|
||
| var dest = new T[length]; | ||
| Array.Copy(array, offset, dest, 0, length); | ||
| return dest; | ||
| } | ||
| else | ||
| { | ||
| // The array is actually a U[] where U:T. | ||
| var dest = (T[])Array.CreateInstance(array.GetType().GetElementType(), length); | ||
| Array.Copy(array, offset, dest, 0, length); | ||
| return dest; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
5 changes: 5 additions & 0 deletions
5
src/libraries/Microsoft.Bcl.Memory/ref/Microsoft.Bcl.Memory.Forwards.netstandard21.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,5 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Index))] | ||
| [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Range))] |
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
41 changes: 41 additions & 0 deletions
41
src/libraries/Microsoft.Bcl.Memory/ref/Microsoft.Bcl.Memory.netstandard20.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,41 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // ------------------------------------------------------------------------------ | ||
| // Changes to this file must follow the https://aka.ms/api-review process. | ||
| // ------------------------------------------------------------------------------ | ||
|
|
||
| namespace System | ||
| { | ||
| public readonly partial struct Index : System.IEquatable<System.Index> | ||
| { | ||
| private readonly int _dummyPrimitive; | ||
| public Index(int value, bool fromEnd = false) { throw null; } | ||
| public static System.Index End { get { throw null; } } | ||
| public bool IsFromEnd { get { throw null; } } | ||
| public static System.Index Start { get { throw null; } } | ||
| public int Value { get { throw null; } } | ||
| public bool Equals(System.Index other) { throw null; } | ||
| public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } | ||
| public static System.Index FromEnd(int value) { throw null; } | ||
| public static System.Index FromStart(int value) { throw null; } | ||
| public override int GetHashCode() { throw null; } | ||
| public int GetOffset(int length) { throw null; } | ||
| public static implicit operator System.Index (int value) { throw null; } | ||
| public override string ToString() { throw null; } | ||
| } | ||
| public readonly partial struct Range : System.IEquatable<System.Range> | ||
| { | ||
| private readonly int _dummyPrimitive; | ||
| public Range(System.Index start, System.Index end) { throw null; } | ||
| public static System.Range All { get { throw null; } } | ||
| public System.Index End { get { throw null; } } | ||
| public System.Index Start { get { throw null; } } | ||
| public static System.Range EndAt(System.Index end) { throw null; } | ||
| public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } | ||
| public bool Equals(System.Range other) { throw null; } | ||
| public override int GetHashCode() { throw null; } | ||
| public (int Offset, int Length) GetOffsetAndLength(int length) { throw null; } | ||
| public static System.Range StartAt(System.Index start) { throw null; } | ||
| public override string ToString() { throw null; } | ||
| } | ||
| } |
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
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
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
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
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.