Skip to content

[Repo Assist] improve: remove System.Linq from SystemCapability#213

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/improve-remove-linq-systemcapability-2026-04-26-5e21e3d73aef1c8b
Draft

[Repo Assist] improve: remove System.Linq from SystemCapability#213
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/improve-remove-linq-systemcapability-2026-04-26-5e21e3d73aef1c8b

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated PR from Repo Assist.

Removes the using System.Linq; dependency from SystemCapability.cs, replacing three LINQ chains with explicit loops to match the pattern already established throughout the codebase (ExecShellWrapperParser, NodeCapabilities, OpenClawGatewayClient, and others that had LINQ removed in recent PRs).

What changed

ResolveExecutable — PATHEXT extensions list

Before:

extensions.AddRange(pathext.Split(';', StringSplitOptions.RemoveEmptyEntries)
    .Select(e => e.ToLowerInvariant()));

After:

foreach (var e in pathext.Split(';', StringSplitOptions.RemoveEmptyEntries))
    extensions.Add(e.ToLowerInvariant());

Removes the lazy IEnumerable<string> allocation from Enumerable.Select. The List<string> receives elements directly.

HandleExecApprovalsGet — rules summary

Before:

rules = data.Rules.Select(r => new { pattern = ..., ... }).ToArray()

After:

var rulesSummary = new object[rules.Count];
for (var i = 0; i < rules.Count; i++) { ... }
rules = rulesSummary

Pre-allocates the output array to the exact size; avoids the intermediate IEnumerable<> iterator + ToArray() copy.

HandleExecApprovalsSet — shells array parsing

Before:

rule.Shells = shellsEl.EnumerateArray()
    .Where(s => s.ValueKind == JsonValueKind.String)
    .Select(s => s.GetString() ?? "")
    .ToArray();

After:

var shellsList = new List<string>(shellsEl.GetArrayLength());
foreach (var s in shellsEl.EnumerateArray())
{
    if (s.ValueKind == JsonValueKind.String)
        shellsList.Add(s.GetString() ?? "");
}
rule.Shells = shellsList.Count > 0 ? shellsList.ToArray() : null;

Pre-sizes the list from GetArrayLength() (avoids resize), uses a simple guard instead of .Where(), and sets Shells = null for empty arrays (matching the is { Length: > 0 } pattern in ExecApprovalPolicy.Evaluate).

Test Status

  • dotnet test OpenClaw.Shared.Tests652 passed, 20 skipped (unchanged from baseline)
  • No behaviour change; all existing tests pass

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a

Replace three LINQ chains with explicit loops to match the
no-LINQ pattern already established throughout the codebase
(ExecShellWrapperParser, NodeCapabilities, OpenClawGatewayClient, etc.):

- ResolveExecutable: AddRange+Select → foreach+Add when building
  the PATHEXT extensions list; eliminates the lazy IEnumerable
  allocation from Enumerable.Select.

- HandleExecApprovalsGet: Rules.Select(...).ToArray() → indexed
  for-loop into pre-allocated object[rules.Count]; removes the
  intermediate IEnumerable<> iterator allocation.

- HandleExecApprovalsSet shells parsing:
  .Where(...).Select(...).ToArray() → foreach with explicit
  ValueKind guard; pre-sizes the List<string> from
  GetArrayLength() to avoid re-allocation on resize.

Also removes the now-unused 'using System.Linq;' import.

No behaviour change; 652 Shared tests pass, 20 skipped.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants