-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Dev/erarndt/span based string builder #12100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev/erarndt/span based string builder #12100
Conversation
…rndt/spanBasedStringBuilder
…rndt/spanBasedStringBuilder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes SpanBasedStringBuilder by adding direct indexing, enumeration, equality, and character-based trim operations to reduce intermediate allocations, and updates Expander to use these new features for argument parsing.
- Added an indexer,
GetEnumerator,Equalsoverloads, andTrim(char)methods inSpanBasedStringBuilder - Refactored
Expanderto remove temporary quote-character arrays and leverageSpanBasedStringBuildermethods
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/StringTools/SpanBasedStringBuilder.cs | Enhanced with an indexer, enumerator, span- and string-based Equals, and Trim(char) overloads to avoid allocations |
| src/Build/Evaluation/Expander.cs | Updated argument parsing to call SpanBasedStringBuilder APIs directly, removed static quote-char arrays |
Comments suppressed due to low confidence (3)
src/StringTools/SpanBasedStringBuilder.cs:123
- [nitpick] The public indexer is missing XML documentation. Consider adding a
tag explaining how indexing works and which exceptions are thrown.
public char this[int index]
src/StringTools/SpanBasedStringBuilder.cs:312
- [nitpick] This overload is missing XML documentation. Add a
description matching the existing parameterless TrimStart for consistency.
public void TrimStart(char c)
src/StringTools/SpanBasedStringBuilder.cs:123
- Introduce unit tests covering the new indexer, all Equals overloads, and Trim(char) methods to validate behavior and prevent regressions.
public char this[int index]
An internal tool recently had trouble updating to .NET 10 because it deployed a stale local copy of `Microsoft.NET.StringTools.dll` that was working (by coincidence) throughout .NET 9 but failed after dotnet/msbuild#12100 added some API surface to StringTools and used it.
* Add StringTools to do-not-deploy list An internal tool recently had trouble updating to .NET 10 because it deployed a stale local copy of `Microsoft.NET.StringTools.dll` that was working (by coincidence) throughout .NET 9 but failed after dotnet/msbuild#12100 added some API surface to StringTools and used it. * Add nuget dependency as well --------- Co-authored-by: Chet Husk <[email protected]>
Context
The usage patterns in
ExtractFunctionArguments()cause significant allocations due to repeated, small, intermediate allocations. Luckily, we can updateSpanBasedStringBuilderto avoid a majority of these allocations.Before:

After:

Changes Made
Testing
Notes