Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions eng/CodeAnalysis.src.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,12 @@ dotnet_diagnostic.CA1860.severity = warning
# CA1861: Avoid constant arrays as arguments
dotnet_diagnostic.CA1861.severity = warning

# CA1862: Prefer using 'StringComparer'/'StringComparison' to perform case-insensitive string comparisons
dotnet_diagnostic.CA1862.severity = warning

# CA1864: Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
dotnet_diagnostic.CA1864.severity = warning

# CA2000: Dispose objects before losing scope
dotnet_diagnostic.CA2000.severity = none

Expand Down
6 changes: 6 additions & 0 deletions eng/CodeAnalysis.test.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,12 @@ dotnet_diagnostic.CA1860.severity = none
# CA1861: Avoid constant arrays as arguments
dotnet_diagnostic.CA1861.severity = none

# CA1862: Prefer using 'StringComparer'/'StringComparison' to perform case-insensitive string comparisons
dotnet_diagnostic.CA1862.severity = none

# CA1864: Prefer the 'IDictionary.TryAdd(TKey, TValue)' method
dotnet_diagnostic.CA1864.severity = none

# CA2000: Dispose objects before losing scope
dotnet_diagnostic.CA2000.severity = none

Expand Down
15 changes: 5 additions & 10 deletions src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ private string ComputeMangledTypeName(TypeDesc type)
lock (this)
{
// Ensure that name is unique and update our tables accordingly.
if (!_mangledTypeNames.ContainsKey(type))
_mangledTypeNames.Add(type, mangledName);
_mangledTypeNames.TryAdd(type, mangledName);
}

return mangledName;
Expand Down Expand Up @@ -386,8 +385,7 @@ public override Utf8String GetMangledMethodName(MethodDesc method)

lock (this)
{
if (!_mangledMethodNames.ContainsKey(method))
_mangledMethodNames.Add(method, utf8MangledName);
_mangledMethodNames.TryAdd(method, utf8MangledName);
}

return utf8MangledName;
Expand Down Expand Up @@ -557,8 +555,7 @@ private Utf8String ComputeUnqualifiedMangledMethodName(MethodDesc method)
{
lock (this)
{
if (!_unqualifiedMangledMethodNames.ContainsKey(method))
_unqualifiedMangledMethodNames.Add(method, utf8MangledName);
_unqualifiedMangledMethodNames.TryAdd(method, utf8MangledName);
}
}

Expand Down Expand Up @@ -622,8 +619,7 @@ private Utf8String ComputeMangledFieldName(FieldDesc field)

lock (this)
{
if (!_mangledFieldNames.ContainsKey(field))
_mangledFieldNames.Add(field, utf8MangledName);
_mangledFieldNames.TryAdd(field, utf8MangledName);
}

return utf8MangledName;
Expand All @@ -644,8 +640,7 @@ public override string GetMangledStringName(string literal)

lock (this)
{
if (!_mangledStringLiterals.ContainsKey(literal))
_mangledStringLiterals.Add(literal, mangledName);
_mangledStringLiterals.TryAdd(literal, mangledName);
}

return mangledName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public IBCProfileData(MibcConfig config, bool partialNGen, IEnumerable<MethodPro
MethodProfileData[] dataArray = methodData.ToArray();
foreach (MethodProfileData data in dataArray)
{
if (!_methodData.ContainsKey(data.Method))
{
_methodData.Add(data.Method, data);
}
_methodData.TryAdd(data.Method, data);
}
_partialNGen = partialNGen;
_config = config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ private void PublishedInstrument(Instrument instrument, MeterListener _)
if (state != null)
{
_beginInstrumentMeasurements(instrument);

#pragma warning disable CA1864 // Prefer the 'IDictionary.TryAdd(TKey, TValue)' method. IDictionary.TryAdd() is not available in one of the builds
if (!_instruments.ContainsKey(instrument))
#pragma warning restore CA1864
{
// This has side effects that prompt MeasurementsCompleted
// to be called if this is called multiple times on an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ private static ProcessInfo[] GetProcessInfos(PerformanceCounterLib library, int
}
else
{
if (processInfos.ContainsKey(processInfo.ProcessId))
if (!processInfos.TryAdd(processInfo.ProcessId, processInfo))
{
// We've found two entries in the perfcounters that claim to be the
// same process. We throw an exception. Is this really going to be
Expand All @@ -549,7 +549,6 @@ private static ProcessInfo[] GetProcessInfos(PerformanceCounterLib library, int
}
}
processInfo.ProcessName = instanceName.ToString();
processInfos.Add(processInfo.ProcessId, processInfo);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,10 @@ private bool MoveNextForeign(ref bool outerNeedToRetry)
if (null == foreignSid.sidIssuerName)
{
// create and return the unknown principal if it is not yet present in usersVisited
if (!_usersVisited.ContainsKey(foreignSid.name))
if (_usersVisited.TryAdd(foreignSid.name, true))
{
byte[] sid = Utils.ConvertNativeSidToByteArray(foreignSid.pSid);
UnknownPrincipal unknownPrincipal = UnknownPrincipal.CreateUnknownPrincipal(_storeCtx.OwningContext, sid, foreignSid.name);
_usersVisited.Add(foreignSid.name, true);
this.current = null;
_currentForeignDE = null;
_currentForeignPrincipal = unknownPrincipal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ private void ReplaceSchemaInfo(XObject o, XmlSchemaInfo schemaInfo)
XmlSchemaInfo? si = o.Annotation<XmlSchemaInfo>();
if (si != null)
{
if (!schemaInfos.ContainsKey(si))
{
schemaInfos.Add(si, si);
}
schemaInfos.TryAdd(si, si);
o.RemoveAnnotations<XmlSchemaInfo>();
}
if (!schemaInfos.TryGetValue(schemaInfo, out si))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1229,17 +1229,11 @@ private void ParseEntityDecl()

if (isParamEntity)
{
if (!_schemaInfo.ParameterEntities.ContainsKey(entityName))
{
_schemaInfo.ParameterEntities.Add(entityName, entity);
}
_schemaInfo.ParameterEntities.TryAdd(entityName, entity);
}
else
{
if (!_schemaInfo.GeneralEntities.ContainsKey(entityName))
{
_schemaInfo.GeneralEntities.Add(entityName, entity);
}
_schemaInfo.GeneralEntities.TryAdd(entityName, entity);
}
entity.DeclaredInExternal = !ParsingInternalSubset;
entity.ParsingInProgress = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,17 +861,11 @@ private async Task ParseEntityDeclAsync()

if (isParamEntity)
{
if (!_schemaInfo.ParameterEntities.ContainsKey(entityName))
{
_schemaInfo.ParameterEntities.Add(entityName, entity);
}
_schemaInfo.ParameterEntities.TryAdd(entityName, entity);
}
else
{
if (!_schemaInfo.GeneralEntities.ContainsKey(entityName))
{
_schemaInfo.GeneralEntities.Add(entityName, entity);
}
_schemaInfo.GeneralEntities.TryAdd(entityName, entity);
}
entity.DeclaredInExternal = !ParsingInternalSubset;
entity.ParsingInProgress = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,7 @@ private void Output(SchemaInfo schemaInfo)
SchemaNotation no = new SchemaNotation(notation.QualifiedName);
no.SystemLiteral = notation.System;
no.Pubid = notation.Public;
if (!schemaInfo.Notations.ContainsKey(no.Name.Name))
{
schemaInfo.Notations.Add(no.Name.Name, no);
}
schemaInfo.Notations.TryAdd(no.Name.Name, no);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,7 @@ internal void Add(SchemaInfo sinfo, ValidationEventHandler? eventhandler)

foreach (string tns in sinfo.TargetNamespaces.Keys)
{
if (!_targetNamespaces.ContainsKey(tns))
{
_targetNamespaces.Add(tns, true);
}
_targetNamespaces.TryAdd(tns, true);
}

foreach (KeyValuePair<XmlQualifiedName, SchemaElementDecl> entry in sinfo._elementDecls)
Expand All @@ -321,17 +318,11 @@ internal void Add(SchemaInfo sinfo, ValidationEventHandler? eventhandler)
}
foreach (SchemaAttDef attdef in sinfo.AttributeDecls.Values)
{
if (!_attributeDecls.ContainsKey(attdef.Name))
{
_attributeDecls.Add(attdef.Name, attdef);
}
_attributeDecls.TryAdd(attdef.Name, attdef);
}
foreach (SchemaNotation notation in sinfo.Notations.Values)
{
if (!Notations.ContainsKey(notation.Name.Name))
{
Notations.Add(notation.Name.Name, notation);
}
Notations.TryAdd(notation.Name.Name, notation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,7 @@ private void Output(SchemaInfo schemaInfo)
SchemaNotation no = new SchemaNotation(notation!.QualifiedName);
no.SystemLiteral = notation.System;
no.Pubid = notation.Public;
if (!schemaInfo.Notations.ContainsKey(no.Name.Name))
{
schemaInfo.Notations.Add(no.Name.Name, no);
}
schemaInfo.Notations.TryAdd(no.Name.Name, no);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1051,11 +1051,7 @@ private static void XDR_BuildAttributeType_Name(XdrBuilder builder, object obj,
// Global AttributeTypes are URN qualified so that we can look them up across schemas.
qname = new XmlQualifiedName(qname.Name, builder._TargetNamespace);
builder._AttributeDef._AttDef.Name = qname;
if (!builder._SchemaInfo.AttributeDecls.ContainsKey(qname))
{
builder._SchemaInfo.AttributeDecls.Add(qname, builder._AttributeDef._AttDef);
}
else
if (!builder._SchemaInfo.AttributeDecls.TryAdd(qname, builder._AttributeDef._AttDef))
{
builder.SendValidationEvent(SR.Sch_DupAttribute, XmlQualifiedName.ToString(qname.Name, prefix));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ private void GroupResolvedFilesToPublish(

foreach (var candidate in resolvedFilesToPublish)
{
#pragma warning disable CA1864 // Prefer the 'IDictionary.TryAdd(TKey, TValue)' method. Dictionary.TryAdd() not available in .Net framework.
Copy link
Contributor Author

@buyaa-n buyaa-n Jul 11, 2023

Choose a reason for hiding this comment

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

We might want to if-def .Net framework build and apply the fix

if (AssetsComputingHelper.ShouldFilterCandidate(candidate, TimeZoneSupport, InvariantGlobalization, CopySymbols, customIcuCandidateFilename, EnableThreads, EmitSourceMap, out var reason))
{
Log.LogMessage(MessageImportance.Low, "Skipping asset '{0}' because '{1}'", candidate.ItemSpec, reason);
Expand Down Expand Up @@ -654,6 +655,7 @@ private void GroupResolvedFilesToPublish(
}
continue;
}
#pragma warning restore CA1864
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ protected override void ProcessMethod (MethodDefinition method)
methods.Add (method);
}

if (!fields.ContainsKey (field))
fields.Add (field, access);
else
if (!fields.TryAdd (field, access))
fields[field] |= access;
}
}
Expand Down