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

Fix concurrent collections CA1836 rule violations #40629

Merged
merged 2 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<Rule Id="CA1833" Action="Warning" /> <!-- Use AsSpan or AsMemory instead of Range-based indexers when appropriate -->
<Rule Id="CA1834" Action="Warning" /> <!-- Consider using 'StringBuilder.Append(char)' when applicable. -->
<Rule Id="CA1835" Action="Warning" /> <!-- Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' -->
<Rule Id="CA1836" Action="Info" /> <!-- Prefer IsEmpty over Count -->
<Rule Id="CA1836" Action="Warning" /> <!-- Prefer IsEmpty over Count -->
<Rule Id="CA1837" Action="Warning" /> <!-- Use 'Environment.ProcessId' -->
<Rule Id="CA1838" Action="Warning" /> <!-- Avoid 'StringBuilder' parameters for P/Invokes -->
<Rule Id="CA2000" Action="None" /> <!-- Dispose objects before losing scope -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal int Clear()
ConcurrentDictionary<DbConnectionPoolIdentity, DbConnectionPool>? oldPoolCollection = null;
lock (this)
{
if (_poolCollection.Count > 0)
if (!_poolCollection.IsEmpty)
{
oldPoolCollection = _poolCollection;
_poolCollection = new ConcurrentDictionary<DbConnectionPoolIdentity, DbConnectionPool>();
Expand Down Expand Up @@ -232,7 +232,7 @@ internal bool Prune()
// to avoid conflict with DbConnectionFactory.CreateConnectionPoolGroup replacing pool entry
lock (this)
{
if (_poolCollection.Count > 0)
if (!_poolCollection.IsEmpty)
{
var newPoolCollection = new ConcurrentDictionary<DbConnectionPoolIdentity, DbConnectionPool>();

Expand Down Expand Up @@ -267,7 +267,7 @@ internal bool Prune()

// must be pruning thread to change state and no connections
// otherwise pruning thread risks making entry disabled soon after user calls ClearPool
if (0 == _poolCollection.Count)
if (_poolCollection.IsEmpty)
{
if (PoolGroupStateActive == _state)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ internal void CleanupTimer_Tick()
}

// We didn't totally empty the cleanup queue, try again later.
if (_expiredHandlers.Count > 0)
if (!_expiredHandlers.IsEmpty)
{
StartCleanupTimer();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ internal int Clear()
ConcurrentDictionary<DbConnectionPoolIdentity, DbConnectionPool>? oldPoolCollection = null;
lock (this)
{
if (_poolCollection.Count > 0)
if (!_poolCollection.IsEmpty)
{
oldPoolCollection = _poolCollection;
_poolCollection = new ConcurrentDictionary<DbConnectionPoolIdentity, DbConnectionPool>();
Expand Down Expand Up @@ -266,7 +266,7 @@ internal bool Prune()
// to avoid conflict with DbConnectionFactory.CreateConnectionPoolGroup replacing pool entry
lock (this)
{
if (_poolCollection.Count > 0)
if (!_poolCollection.IsEmpty)
{
var newPoolCollection = new ConcurrentDictionary<DbConnectionPoolIdentity, DbConnectionPool>();

Expand Down Expand Up @@ -309,7 +309,7 @@ internal bool Prune()

// must be pruning thread to change state and no connections
// otherwise pruning thread risks making entry disabled soon after user calls ClearPool
if (0 == _poolCollection.Count)
if (_poolCollection.IsEmpty)
{
if (PoolGroupStateActive == _state)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public bool Equals(SslCredKey other)
//
internal static SafeFreeCredentials? TryCachedCredential(byte[]? thumbPrint, SslProtocols sslProtocols, bool isServer, EncryptionPolicy encryptionPolicy)
{
if (s_cachedCreds.Count == 0)
if (s_cachedCreds.IsEmpty)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(null, $"Not found, Current Cache Count = {s_cachedCreds.Count}");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public static void Invoke(ParallelOptions parallelOptions, params Action[] actio
}

// If we have encountered any exceptions, then throw.
if ((exceptionQ != null) && (exceptionQ.Count > 0))
if ((exceptionQ != null) && (!exceptionQ.IsEmpty))
{
ThrowSingleCancellationExceptionOrOtherException(exceptionQ, parallelOptions.CancellationToken,
new AggregateException(exceptionQ));
Expand Down