Override IndentedTextWriter APIs that write spans.#130586
Open
teo-tsirpanis wants to merge 4 commits into
Open
Override IndentedTextWriter APIs that write spans.#130586teo-tsirpanis wants to merge 4 commits into
IndentedTextWriter APIs that write spans.#130586teo-tsirpanis wants to merge 4 commits into
Conversation
Saves an array pool rent/return cycle and copying.
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-runtime |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates System.CodeDom.Compiler.IndentedTextWriter to override the span-based TextWriter write APIs so span writes can be forwarded directly to the inner writer without the base TextWriter array-pool rent/copy path.
Changes:
- Add
IndentedTextWriter.Write(ReadOnlySpan<char>)andWriteLine(ReadOnlySpan<char>)overrides in CoreLib. - Add the corresponding members to the
System.Runtimereference assembly forIndentedTextWriter.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/CodeDom/Compiler/IndentedTextWriter.cs | Adds span-based Write / WriteLine overrides to avoid the TextWriter pooling/copy path. |
| src/libraries/System.Runtime/ref/System.Runtime.cs | Updates the public contract to include the new IndentedTextWriter override members. |
| public override void Write(char value) { } | ||
| public override void Write(char[]? buffer) { } | ||
| public override void Write(char[] buffer, int index, int count) { } | ||
| public override void Write(ReadOnlySpan<char> buffer) { } |
Contributor
Author
There was a problem hiding this comment.
I don't think overriding a method needs approval.
Fixes race conditions if a synchronous operation is queued to run on another thread.
8569c2b to
1f0b6d5
Compare
Comment on lines
8123
to
8126
| public override void Write(char[]? buffer) { } | ||
| public override void Write(char[] buffer, int index, int count) { } | ||
| public override void Write(System.ReadOnlySpan<char> buffer) { } | ||
| public override void Write(double value) { } |
Comment on lines
+139
to
+143
| public override void Write(ReadOnlySpan<char> buffer) | ||
| { | ||
| OutputTabs(); | ||
| _writer.Write(buffer); | ||
| } |
Comment on lines
8121
to
8126
| @@ -8122,6 +8122,7 @@ public override void Write(bool value) { } | |||
| public override void Write(char value) { } | |||
| public override void Write(char[]? buffer) { } | |||
| public override void Write(char[] buffer, int index, int count) { } | |||
| public override void Write(System.ReadOnlySpan<char> buffer) { } | |||
| public override void Write(double value) { } | |||
Comment on lines
+139
to
+143
| public override void Write(ReadOnlySpan<char> buffer) | ||
| { | ||
| OutputTabs(); | ||
| _writer.Write(buffer); | ||
| } |
3 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Saves an array pool rent/return cycle and copying.