Skip to content

Commit 6c14d6b

Browse files
authored
Allocate slightly less in ImmutableArrayExtensions.ConditionallyDeOrder (#78235)
This method currently allocates two arrays (once during the ToArray call, the other in the AsImmutable call). This is generally not a problem as this is debug only code, but this method is called very frequently, so I'll change the line to make this method only allocate the array once.
1 parent 3683d8b commit 6c14d6b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Compilers/Core/Portable/Collections/ImmutableArrayExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,8 @@ internal static ImmutableArray<T> ConditionallyDeOrder<T>(this ImmutableArray<T>
847847
var temp = copy[0];
848848
copy[0] = copy[last];
849849
copy[last] = temp;
850-
return copy.AsImmutable();
850+
851+
return ImmutableCollectionsMarshal.AsImmutableArray(copy);
851852
}
852853
#endif
853854
return array;

0 commit comments

Comments
 (0)