| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
There was a problem hiding this comment.
This PR refines several LINQ usage patterns in the ScriptAnalyzer engine and built-in rules to avoid unnecessary enumerations and iterator allocations in common execution paths.
Changes:
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Rules/AvoidMultipleTypeAttributes.cs | Uses Count(predicate) instead of Where(...).Count() when checking type-constraint attribute count. |
| Engine/Settings.cs | Uses Any() for hashtable-AST presence checks while parsing settings files. |
| Engine/ScriptAnalyzer.cs | Uses List<T>.Count properties and switches hashtable-AST emptiness checks to Any(). |
| Engine/Generic/RuleSuppression.cs | Uses Any() for suppression target resolution emptiness checks. |
Engine/Settings.cs:461
IEnumerable<Ast> hashTableAsts = profileAst.FindAll(item => item is HashtableAst, false);
// no hashtable, raise warning
if (!hashTableAsts.Any())
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.InvalidProfile, settingsFilePath));
}
HashtableAst hashTableAst = hashTableAsts.First() as HashtableAst;
Engine/ScriptAnalyzer.cs:621
IEnumerable<Ast> hashTableAsts = profileAst.FindAll(item => item is HashtableAst, false);
// no hashtable, raise warning
if (!hashTableAsts.Any())
{
writer.WriteError(new ErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.InvalidProfile, profile)),
Strings.ConfigurationFileHasNoHashTable, ErrorCategory.ResourceUnavailable, profile));
hasError = true;
}
else
{
HashtableAst hashTableAst = hashTableAsts.First() as HashtableAst;
Engine/Generic/RuleSuppression.cs:361
if (!targetAsts.Any())
{
if (String.IsNullOrWhiteSpace(scopeAst.Extent.File))
{
ruleSupp.Error = String.Format(CultureInfo.CurrentCulture, Strings.RuleSuppressionErrorFormatScriptDefinition, ruleSupp.StartAttributeLine,
String.Format(Strings.TargetCannotBeFoundError, ruleSupp.Target, ruleSupp.Scope));
}
else
{
ruleSupp.Error = String.Format(CultureInfo.CurrentCulture, Strings.RuleSuppressionErrorFormat, ruleSupp.StartAttributeLine,
System.IO.Path.GetFileName(scopeAst.Extent.File), String.Format(Strings.TargetCannotBeFoundError, ruleSupp.Target, ruleSupp.Scope));
}
result.Add(ruleSupp);
continue;
}
foreach (Ast targetAst in targetAsts)
{
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Lol it's doing it how I'd do it.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
NOTE: This was created using GH Copilot agent when being asked for optimizations. They seem sensible. Not sure if we will see the benefit of it as many LINQ methods have internal optimisation to use Count property if available but having code the right way seems better practice. Below is Copilot's summary:
Replaced inefficient LINQ patterns with performant alternatives across core analysis paths.
Changes
List count checks (ScriptAnalyzer.cs:274-276)
Enumerable emptiness checks (ScriptAnalyzer.cs:616, RuleSuppression.cs:345, Settings.cs:456)
Filtered counting (AvoidMultipleTypeAttributes.cs:40)
Impact: Eliminates unnecessary enumerations in settings parsing and per-rule execution paths. Any() short-circuits on first match; Count(predicate) eliminates intermediate allocations.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
PR Checklist