mirror of https://github.com/dotnet/runtime
Enable new analyzer CA1868: 'Unnecessary call to 'Contains' for sets' and fix findings (#89652)
This commit is contained in:
parent
d5c4a4e6b7
commit
4ed355098d
|
@ -483,6 +483,9 @@ dotnet_diagnostic.CA1863.severity = suggestion
|
|||
# CA1864: Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
|
||||
dotnet_diagnostic.CA1864.severity = warning
|
||||
|
||||
# CA1868: Unnecessary call to 'Contains' for sets
|
||||
dotnet_diagnostic.CA1868.severity = warning
|
||||
|
||||
# CA2000: Dispose objects before losing scope
|
||||
dotnet_diagnostic.CA2000.severity = none
|
||||
|
||||
|
|
|
@ -480,6 +480,9 @@ dotnet_diagnostic.CA1863.severity = none
|
|||
# CA1864: Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
|
||||
dotnet_diagnostic.CA1864.severity = none
|
||||
|
||||
# CA1868: Unnecessary call to 'Contains' for sets
|
||||
dotnet_diagnostic.CA1868.severity = none
|
||||
|
||||
# CA2000: Dispose objects before losing scope
|
||||
dotnet_diagnostic.CA2000.severity = none
|
||||
|
||||
|
|
|
@ -113,9 +113,8 @@ namespace ILCompiler.DependencyAnalysis
|
|||
{
|
||||
foreach (var module in allModules)
|
||||
{
|
||||
if (!markedModules.Contains(module))
|
||||
if (markedModules.Add(module))
|
||||
{
|
||||
markedModules.Add(module);
|
||||
if (modulesWithCctor.Contains(module.Module))
|
||||
sortedModules.Add(module.Module);
|
||||
break;
|
||||
|
|
|
@ -158,10 +158,8 @@ namespace ILCompiler.DependencyAnalysisFramework
|
|||
void IDependencyAnalyzerLogEdgeVisitor<DependencyContextType>.VisitEdge(DependencyNodeCore<DependencyContextType> nodeDepender, DependencyNodeCore<DependencyContextType> nodeDependerOther, DependencyNodeCore<DependencyContextType> nodeDependedOn, string reason)
|
||||
{
|
||||
var combinedNode = new Tuple<DependencyNodeCore<DependencyContextType>, DependencyNodeCore<DependencyContextType>>(nodeDepender, nodeDependerOther);
|
||||
if (!_combinedNodesEdgeVisited.Contains(combinedNode))
|
||||
if (_combinedNodesEdgeVisited.Add(combinedNode))
|
||||
{
|
||||
_combinedNodesEdgeVisited.Add(combinedNode);
|
||||
|
||||
_xmlWrite.WriteStartElement("Link");
|
||||
_xmlWrite.WriteAttributeString("Source", _nodeMappings[nodeDepender].ToString());
|
||||
_xmlWrite.WriteAttributeString("Target", _nodeMappings[combinedNode].ToString());
|
||||
|
|
|
@ -185,14 +185,7 @@ namespace System.ComponentModel.Composition.ReflectionModel
|
|||
}
|
||||
else
|
||||
{
|
||||
if (candidates.Contains(candidatePart))
|
||||
{
|
||||
alreadyProcessed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
candidates.Add(candidatePart);
|
||||
}
|
||||
alreadyProcessed |= !candidates.Add(candidatePart);
|
||||
}
|
||||
if (!alreadyProcessed)
|
||||
{
|
||||
|
|
|
@ -472,9 +472,8 @@ namespace System.Diagnostics.Metrics
|
|||
}
|
||||
}
|
||||
|
||||
if (!_sharedSessionClientIds.Contains(clientId))
|
||||
if (_sharedSessionClientIds.Add(clientId))
|
||||
{
|
||||
_sharedSessionClientIds.Add(clientId);
|
||||
Interlocked.Increment(ref _sharedSessionRefCount);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,9 +122,8 @@ namespace Microsoft.Android.Build
|
|||
string rootPath = Path.GetDirectoryName(lib)!;
|
||||
string libName = Path.GetFileName(lib);
|
||||
|
||||
if (!libDirs.Contains(rootPath))
|
||||
if (libDirs.Add(rootPath))
|
||||
{
|
||||
libDirs.Add(rootPath);
|
||||
ret.Append($"-L {rootPath} ");
|
||||
}
|
||||
ret.Append($"-l:{libName} ");
|
||||
|
|
|
@ -79,8 +79,7 @@ namespace ILLink.Shared
|
|||
var values = new HashSet<DynamicallyAccessedMemberTypes> (
|
||||
Enum.GetValues (typeof (DynamicallyAccessedMemberTypes))
|
||||
.Cast<DynamicallyAccessedMemberTypes> ());
|
||||
if (!values.Contains (DynamicallyAccessedMemberTypes.Interfaces))
|
||||
values.Add (DynamicallyAccessedMemberTypes.Interfaces);
|
||||
values.Add (DynamicallyAccessedMemberTypes.Interfaces);
|
||||
return values.ToArray ();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue