Add ReadOnlySpan constructors to BitArray - #131500
Draft
joshuajyue wants to merge 1 commit into
Draft
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4236475d-0243-488d-93d8-cd78e94d532b
|
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
There was a problem hiding this comment.
Pull request overview
Adds new ReadOnlySpan<T>-based constructors to System.Collections.BitArray to enable allocation-free construction from span-backed inputs, while preserving existing array-constructor behaviors by routing them through the new span overloads. This extends the public System.Collections contract and provides test coverage for span-specific scenarios (slices, stackalloc, copy semantics, and SIMD boundary safety).
Changes:
- Added
BitArray(ReadOnlySpan<bool>),BitArray(ReadOnlySpan<byte>), andBitArray(ReadOnlySpan<int>)constructors and routed existing array constructors through them. - Updated the
System.Collectionsreference assembly to expose the new public constructors. - Expanded unit tests to validate span parity with array constructors, slicing/stackalloc usage, source independence, non-canonical bool handling, and vector boundary safety.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Collections/BitArray.cs | Implements the new span constructors and reuses them from existing array constructors without changing established behaviors (null/overflow handling, packing semantics). |
| src/libraries/System.Collections/tests/BitArray/BitArray_CtorTests.cs | Adds coverage for span constructors (slices, stackalloc, copy semantics, non-canonical bools, and BoundedMemory OOB checks). |
| src/libraries/System.Collections/ref/System.Collections.cs | Adds the new public constructor signatures to the ref surface for System.Collections.BitArray. |
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
ReadOnlySpan<bool>,ReadOnlySpan<byte>, andReadOnlySpan<int>constructors toBitArray.Fixes #80263
Validation
BitArray_CtorTestspassed with default hardware intrinsicsBitArray_CtorTestspassed withDOTNET_EnableAVX2=0BitArray_CtorTestspassed withDOTNET_EnableHWIntrinsic=0System.Collectionstests passedPerformance
Full BenchmarkDotNet results from Windows ARM64 Release:
span.ToArray()workaround across the measured sizes.Note
This pull request description was generated with GitHub Copilot.