Simplify string concatenation by jnyrup · Pull Request #27569 · PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Open
wants to merge 1 commit into
Conversation
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
- PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- Summarized changes
- Make sure all
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header - This PR is ready to merge. If this PR is a work in progress, please open this as a Draft Pull Request and mark it as Ready to Review when it is ready to merge.
- Breaking changes
- None
- OR
- Experimental feature(s) needed
- Experimental feature name(s):
- User-facing changes
- Not Applicable
- OR
- Documentation needed
- Issue filed:
- Testing - New and feature
- N/A or can only be tested interactively
- OR
- Make sure you've added a new test if existing tests do not effectively test the code changed
Copilot AI review requested due to automatic review settings
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 singlestring.Concat(...)call. - Removed manual capacity calculation / preallocation.
| .Append(str, startOffset, length) | ||
| .Append(appendStr) | ||
| .ToString(); | ||
| return string.Concat(prependStr, str.AsSpan(startOffset, length), appendStr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters