Skip to content

Commit 474e28b

Browse files
bergmeisterCopilotCopilot
authored
Optimise LINQ queries (#2160)
* Initial plan * Optimize LINQ operations for better performance Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> * Update Rules/AvoidMultipleTypeAttributes.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Rules/AvoidMultipleTypeAttributes.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b3653a9 commit 474e28b

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
@@ -340,7 +340,7 @@ public static List<RuleSuppression> GetSuppressions(IEnumerable<AttributeAst> at
340340

341341
if (targetAsts != null)
342342
{
343-
if (targetAsts.Count() == 0)
343+
if (!targetAsts.Any())
344344
{
345345
if (String.IsNullOrWhiteSpace(scopeAst.Extent.File))
346346
{

Engine/ScriptAnalyzer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ internal bool ParseProfile(object profileObject, PathIntrinsics path, IOutputWri
267267
return false;
268268
}
269269

270-
this.severity = (severityList.Count() == 0) ? null : severityList.ToArray();
271-
this.includeRule = (includeRuleList.Count() == 0) ? null : includeRuleList.ToArray();
272-
this.excludeRule = (excludeRuleList.Count() == 0) ? null : excludeRuleList.ToArray();
270+
this.severity = (severityList.Count == 0) ? null : severityList.ToArray();
271+
this.includeRule = (includeRuleList.Count == 0) ? null : includeRuleList.ToArray();
272+
this.excludeRule = (excludeRuleList.Count == 0) ? null : excludeRuleList.ToArray();
273273
if (settings != null
274274
&& settings.ContainsKey("Rules"))
275275
{
@@ -609,7 +609,7 @@ private bool ParseProfileString(string profile, PathIntrinsics path, IOutputWrit
609609
IEnumerable<Ast> hashTableAsts = profileAst.FindAll(item => item is HashtableAst, false);
610610

611611
// no hashtable, raise warning
612-
if (hashTableAsts.Count() == 0)
612+
if (!hashTableAsts.Any())
613613
{
614614
writer.WriteError(new ErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.InvalidProfile, profile)),
615615
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.OfType<TypeConstraintAst>().Skip(1).Any())
4141
{
4242
yield return new DiagnosticRecord(
4343
String.Format(CultureInfo.CurrentCulture, Strings.AvoidMultipleTypeAttributesError, paramAst.Name),

0 commit comments

Comments
 (0)