Skip to content

Simplify string concatenation#27569

Open
jnyrup wants to merge 1 commit into
PowerShell:masterfrom
jnyrup:coalesce
Open

Simplify string concatenation#27569
jnyrup wants to merge 1 commit into
PowerShell:masterfrom
jnyrup:coalesce

Conversation

@jnyrup
Copy link
Copy Markdown

@jnyrup jnyrup commented Jun 7, 2026

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
@jnyrup jnyrup requested a review from a team as a code owner June 7, 2026 17:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants