-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[API Proposal]: Create array from array type #88620
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
Changes from 5 commits
626a750
9305288
f0b2424
58467db
f90fda6
824aabe
8296fe6
d83dd4e
f32e6e5
8a9e015
31e43a9
387d0c5
0ede3bd
4816e63
8a9d585
5845090
87d756d
1f67190
39536c3
2429e23
1a6de0f
8ce5332
19271ef
85a44ff
10660c1
ad50dd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ | |
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Reflection; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
@@ -18,6 +17,28 @@ public abstract partial class Array : ICloneable, IList, IStructuralComparable, | |
| [MethodImpl(MethodImplOptions.InternalCall)] | ||
| private static extern unsafe Array InternalCreate(RuntimeType elementType, int rank, int* pLengths, int* pLowerBounds); | ||
|
|
||
| private static unsafe Array InternalCreateFromArrayType(Type arrayType, int rank, int* pLengths, int* pLowerBounds) | ||
| { | ||
| if (rank == 1 && !ContainsLowerBounds(rank, pLowerBounds)) | ||
| { | ||
| return GC.AllocateNewArray(arrayType.TypeHandle.Value, pLengths[0], GC.GC_ALLOC_FLAGS.GC_ALLOC_NO_FLAGS); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We may want to have a new runtime calls for this that will handle the multi-dim case too
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got the next benchmark scores: https://github.com/AlexRadch/Temp/tree/GC_AllocateNewArray_Bench
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, these benchmark shows that I would be interesting to benchmark |
||
| } | ||
|
|
||
| return InternalCreate((arrayType.GetElementType() as RuntimeType)!, rank, pLengths, pLowerBounds); | ||
|
|
||
| static bool ContainsLowerBounds(int rank, int* pLowerBounds) | ||
| { | ||
| if (pLowerBounds != null) | ||
| { | ||
| for (int i = 0; i < rank; i++) | ||
| { | ||
| if (pLowerBounds[i] != 0) | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| private static unsafe void CopyImpl(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, bool reliable) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.