Skip to content
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

Prefer IsEmpty over Count/Any #2091

Merged
merged 2 commits into from
Feb 24, 2023
Merged

Prefer IsEmpty over Count/Any #2091

merged 2 commits into from
Feb 24, 2023

Conversation

jnyrup
Copy link
Contributor

@jnyrup jnyrup commented Feb 24, 2023

Roslyn Aanalyzers reports CA1836: Prefer IsEmpty over Count when available.

E.g. ConcurrentDictionary.IsEmpty has a lock-free fast path, whereas ConcurrentDictionary.Count always acquires all locks.

internal ICollection<WaitTask> WaitTasks { get; set; }
internal ConcurrentSet<WaitTask> WaitTasks { get; set; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the type of this internal property was necessary to get access to IsEmpty at line 146.

Reported by CA1836
@kblok
Copy link
Member

kblok commented Feb 24, 2023

Can you add that to the ruleset?

@jnyrup
Copy link
Contributor Author

jnyrup commented Feb 24, 2023

Can you add that to the ruleset?

Sure!
CA1836 was added in a newer version of Microsoft.NetCore.Analyzers than what is currently referenced.
Upgrading the nuget package triggers several new analyzers, so I've left out upgrading the package from this PR to keep it focused.

@kblok
Copy link
Member

kblok commented Feb 24, 2023

Upgrading the nuget package triggers several new analyzers, so I've left out upgrading the package from this PR to keep it focused.

A PR with that upgrade is welcome! We can mark all failing rules as None, and I can create issues for those.

@jnyrup jnyrup mentioned this pull request Feb 24, 2023
@kblok kblok merged commit f5ca964 into hardkoded:master Feb 24, 2023
@kblok
Copy link
Member

kblok commented Feb 24, 2023

Thank you!

@jnyrup jnyrup deleted the jn/cleanup branch February 25, 2023 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants