Skip to content

Commit

Permalink
Fix concurrent collections CA1836 rule violations (dotnet#40629)
Browse files Browse the repository at this point in the history
* Fix concurrent collections CA1836 rule violations

* Update dogfood analyzer version
  • Loading branch information
jozkee authored Aug 11, 2020
1 parent 2379608 commit bcf3bd3
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion eng/Analyzers.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup Condition="'$(EnableAnalyzers)' == 'true'">
<PackageReference Include="Microsoft.DotNet.CodeAnalysis" Version="$(MicrosoftDotNetCodeAnalysisVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="3.3.0-beta3.20407.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="3.3.0-beta3.20410.1" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164" PrivateAssets="all" />
</ItemGroup>
</Project>
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

0 comments on commit bcf3bd3

Please sign in to comment.