Repository navigation
Conversation
Co-authored-by: Copilot App <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 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-collections |
agammann
reviewed
Nov 8, 2026
agammann
left a comment
There was a problem hiding this comment.
The growth branch now clears retained bytes before Array.Resize copies them, while PopCount() is bounded by the logical length rather than the backing array. The regression cases cover growth both within and beyond capacity, zero length, and the 32-bit boundary, so they exercise the two places where stale bits could surface. I reviewed the diff and tests; I did not run them locally.
This branch has not been deployed
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.
Problem
Fixes finding L40 from #134839: growing
BitArray.Lengthbeyond its backing storage can restore bits removed by an earlier shrink, instead of initializing new elements tofalse.Small reductions in length retain the backing array.
ClearHighExtraBits()clears unused bits in the last valid 32-bit word, but later words may still hold old values. Growth within capacity already clears them; growth beyond capacity only calledArray.Resize, copying the stale data.PopCount()also counted this retained data after shrinking because it scanned the entire backing array.Reproduction and results
Measured using baseline and patched CoreLib with the same Release host:
PopCount()PopCount()The 778 set bits are the 10 retained bits plus 768 stale bits at positions 32–799. Growth to 500 stays within capacity and already works correctly.
Changes
PopCount()to the logical length's 32-bit-aligned storage.Validation
CoreLib builds and the full
System.Collections.Testssuite passed in Release and Checked configurations. Regression tests fail against baseline CoreLib and pass with the fix.Relates to #134839 (L40 only).
Note
This pull request was prepared with GitHub Copilot.