-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Replace some stackallocs with collection expressions #93126
Changes from all commits
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 |
---|---|---|
|
@@ -307,7 +307,7 @@ public static unsafe void Copy(Array sourceArray, int sourceIndex, Array destina | |
if (Rank != indices.Length) | ||
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices); | ||
|
||
return InternalGetValue(GetFlattenedIndex(new ReadOnlySpan<int>(indices))); | ||
return InternalGetValue(GetFlattenedIndex(indices)); | ||
} | ||
|
||
public object? GetValue(int index) | ||
|
@@ -323,15 +323,15 @@ public static unsafe void Copy(Array sourceArray, int sourceIndex, Array destina | |
if (Rank != 2) | ||
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need2DArray); | ||
|
||
return InternalGetValue(GetFlattenedIndex(stackalloc int[] { index1, index2 })); | ||
return InternalGetValue(GetFlattenedIndex([index1, index2])); | ||
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. sharplab, main 12 Oct 2023 allocates. |
||
} | ||
|
||
public object? GetValue(int index1, int index2, int index3) | ||
{ | ||
if (Rank != 3) | ||
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need3DArray); | ||
|
||
return InternalGetValue(GetFlattenedIndex(stackalloc int[] { index1, index2, index3 })); | ||
return InternalGetValue(GetFlattenedIndex([index1, index2, index3])); | ||
} | ||
|
||
public void SetValue(object? value, int index) | ||
|
@@ -347,15 +347,15 @@ public void SetValue(object? value, int index1, int index2) | |
if (Rank != 2) | ||
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need2DArray); | ||
|
||
InternalSetValue(value, GetFlattenedIndex(stackalloc int[] { index1, index2 })); | ||
InternalSetValue(value, GetFlattenedIndex([index1, index2])); | ||
} | ||
|
||
public void SetValue(object? value, int index1, int index2, int index3) | ||
{ | ||
if (Rank != 3) | ||
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_Need3DArray); | ||
|
||
InternalSetValue(value, GetFlattenedIndex(stackalloc int[] { index1, index2, index3 })); | ||
InternalSetValue(value, GetFlattenedIndex([index1, index2, index3])); | ||
} | ||
|
||
public void SetValue(object? value, params int[] indices) | ||
|
@@ -365,7 +365,7 @@ public void SetValue(object? value, params int[] indices) | |
if (Rank != indices.Length) | ||
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices); | ||
|
||
InternalSetValue(value, GetFlattenedIndex(new ReadOnlySpan<int>(indices))); | ||
InternalSetValue(value, GetFlattenedIndex(indices)); | ||
} | ||
|
||
public object? GetValue(long index) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ public static string[] GetLogicalDrives() | |
int count = BitOperations.PopCount((uint)drives); | ||
|
||
string[] result = new string[count]; | ||
Span<char> root = stackalloc char[] { 'A', ':', '\\' }; | ||
Span<char> root = ['A', ':', '\\']; | ||
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. According to sharplab, main 12 Oct 2023 this allocates. Looks like the collection expression only avoid the allocation for ROS, but a ROS can't be used here. |
||
uint d = (uint)drives; | ||
count = 0; | ||
while (d != 0) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,7 +331,7 @@ private static void SurrogateToUpperNLS(char h, char l, out char hr, out char lr | |
Debug.Assert(char.IsHighSurrogate(h)); | ||
Debug.Assert(char.IsLowSurrogate(l)); | ||
|
||
Span<char> chars = stackalloc char[] { h, l }; | ||
ReadOnlySpan<char> chars = [h, l]; | ||
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. sharplab, main 12 Oct 2023 allocates. |
||
Span<char> destination = stackalloc char[2]; | ||
|
||
int written = Ordinal.ToUpperOrdinal(chars, destination); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sharplab, main 12 Oct 2023 allocates.