Skip to content

Refactor WeakReferenceList/CopyOnWriteList as type-safe generic collections #10889

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

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

h3xds1nz
Copy link
Member

@h3xds1nz h3xds1nz commented May 28, 2025

Description

Refactors both CopyOnWriteList and WeakReferenceList as generic type-safe collections.

  • Theoretically, they could have been merged into one but I chose not to currently.

Both lists now support initialization with capacity argument, previously integers passed in (e.g. in PropagateParentOwners) would end up being boxed and the instance of the box being used as a lock. This clearly feels like a mistake.

In ResourceDictionaryDiagnostics I've removed few static fields caching empty (readonly) arrays I didn' see in #10267.

Regarding the removed null-checks:

  • Those are a part of the as casting pattern.
  • The enumerator returns strong, non-null references, hence it will never be null in the first place.
  • I've appropriately null-annotated the adjusted files.

Since ContainsOwner is only called from within the three classes, we can remove the type checks and speed it up.

  • Similarly it can be done for Add/Remove but I'll do that after this is in.

Customer Impact

Improved performance a tiny bit, strongly-typed code and newer practices.

Regression

No.

Testing

Local build, unit tests, testing with sample apps including themes and templates.

Risk

Low to medium, I believe the changes are straightforward and understandable but happy to answer any questions (rather sooner than later).

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz h3xds1nz requested a review from a team as a code owner May 28, 2025 10:29
@dotnet-policy-service dotnet-policy-service bot added the PR metadata: Label to tag PRs, to facilitate with triage label May 28, 2025
@dotnet-policy-service dotnet-policy-service bot added the Community Contribution A label for all community Contributions label May 28, 2025
Copy link

codecov bot commented May 28, 2025

Codecov Report

Attention: Patch coverage is 0% with 249 lines in your changes missing coverage. Please review.

Project coverage is 2.98844%. Comparing base (57fe8ac) to head (3b36966).
Report is 12 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main     #10889          +/-   ##
===================================================
- Coverage   13.48885%   2.98844%   -10.50041%     
===================================================
  Files           3317       3319           +2     
  Lines         664749     664828          +79     
  Branches       74643      74664          +21     
===================================================
- Hits           89667      19868       -69799     
- Misses        572488     644779       +72291     
+ Partials        2594        181        -2413     
Flag Coverage Δ
Debug 2.98844% <0.00000%> (-10.50041%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants