Repository navigation
Conversation
Implement approved API dotnet#121477: Array.CreateFilled<T>(int, T) and Array.CreateFilled<T>(int, Func<int, T>). Fixes dotnet#121477
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-runtime |
Contributor
|
Duplicate of #134745. |
This was referenced Sep 28, 2026
Contributor
Author
Contributor
Author
|
Closing this PR in favor of #134745 since it was opened first. Looking forward to seeing the new Array.CreateFilled API landed in .NET! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements the approved API enhancement from #121477:
Design & Implementation Details
CreateFilled<T>(int length, T value):length >= 0viaArgumentOutOfRangeException.ThrowIfNegative(length).[](Array.Empty<T>()) forlength == 0.GC.AllocateUninitializedArray<T>(length)to bypass zeroing overhead for unmanaged/value types >= 2048 bytes while safely zero-initializing reference types.new Span<T>(array).Fill(value), taking advantage of hardware/SIMD vectorization.CreateFilled<T>(int length, Func<int, T> factory):length >= 0viaArgumentOutOfRangeException.ThrowIfNegative(length).factory != nullviaArgumentNullException.ThrowIfNull(factory).[]forlength == 0.GC.AllocateUninitializedArray<T>(length)and sequentially populates each elementarray[i] = factory(i).factorythrows midway during iteration.src/libraries/System.Runtime/ref/System.Runtime.cs.src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ArrayTests.cs.Fixes #121477