Skip to content

Commit a02b5bb

Browse files
Copilotbergmeister
andcommitted
Optimize LINQ operations for better performance
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
1 parent d6f0b3e commit a02b5bb

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

Engine/Generic/RuleSuppression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public static List<RuleSuppression> GetSuppressions(IEnumerable<AttributeAst> at
342342

343343
if (targetAsts != null)
344344
{
345-
if (targetAsts.Count() == 0)
345+
if (!targetAsts.Any())
346346
{
347347
if (String.IsNullOrWhiteSpace(scopeAst.Extent.File))
348348
{

Engine/ScriptAnalyzer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ internal bool ParseProfile(object profileObject, PathIntrinsics path, IOutputWri
271271
return false;
272272
}
273273

274-
this.severity = (severityList.Count() == 0) ? null : severityList.ToArray();
275-
this.includeRule = (includeRuleList.Count() == 0) ? null : includeRuleList.ToArray();
276-
this.excludeRule = (excludeRuleList.Count() == 0) ? null : excludeRuleList.ToArray();
274+
this.severity = (severityList.Count == 0) ? null : severityList.ToArray();
275+
this.includeRule = (includeRuleList.Count == 0) ? null : includeRuleList.ToArray();
276+
this.excludeRule = (excludeRuleList.Count == 0) ? null : excludeRuleList.ToArray();
277277
if (settings != null
278278
&& settings.ContainsKey("Rules"))
279279
{
@@ -613,7 +613,7 @@ private bool ParseProfileString(string profile, PathIntrinsics path, IOutputWrit
613613
IEnumerable<Ast> hashTableAsts = profileAst.FindAll(item => item is HashtableAst, false);
614614

615615
// no hashtable, raise warning
616-
if (hashTableAsts.Count() == 0)
616+
if (!hashTableAsts.Any())
617617
{
618618
writer.WriteError(new ErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.InvalidProfile, profile)),
619619
Strings.ConfigurationFileHasNoHashTable, ErrorCategory.ResourceUnavailable, profile));

Engine/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ private void parseSettingsFile(string settingsFilePath)
453453
IEnumerable<Ast> hashTableAsts = profileAst.FindAll(item => item is HashtableAst, false);
454454

455455
// no hashtable, raise warning
456-
if (hashTableAsts.Count() == 0)
456+
if (!hashTableAsts.Any())
457457
{
458458
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.InvalidProfile, settingsFilePath));
459459
}

Rules/AvoidMultipleTypeAttributes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
3737
// Iterates all ParamAsts and check the number of its types.
3838
foreach (ParameterAst paramAst in paramAsts)
3939
{
40-
if (paramAst.Attributes.Where(typeAst => typeAst is TypeConstraintAst).Count() > 1)
40+
if (paramAst.Attributes.Count(typeAst => typeAst is TypeConstraintAst) > 1)
4141
{
4242
yield return new DiagnosticRecord(
4343
String.Format(CultureInfo.CurrentCulture, Strings.AvoidMultipleTypeAttributesError, paramAst.Name),

0 commit comments

Comments
 (0)