◐ Shell
clean mode source ↗

Simplify string concatenation by jnyrup · Pull Request #27569 · PowerShell/PowerShell

Skip to content

Navigation Menu

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Open

jnyrup

wants to merge 1 commit into

Conversation

@jnyrup

PR Summary

Simplify string concatenation

PR Context

I originally wanted to fix the missing parentheses in computing the capacity, as + binds stronger than ??, but noticed that the concatenation could be done easier without StringBuilder

int capacity = length + prependStr?.Length ?? 0 + appendStr?.Length ?? 0;

PR Checklist

Copilot AI review requested due to automatic review settings

June 7, 2026 17:13

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR refactors VtSubstring string construction to avoid StringBuilder and instead build the final string via string.Concat using spans.

Changes:

  • Replaced StringBuilder-based concatenation with a single string.Concat(...) call.
  • Removed manual capacity calculation / preallocation.
.Append(str, startOffset, length)
.Append(appendStr)
.ToString();
return string.Concat(prependStr, str.AsSpan(startOffset, length), appendStr);

2 participants

@jnyrup