Skip to content

Avoid TestContext write string allocations#10105

Merged
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/fix-testcontext-write-allocation
Jul 21, 2026
Merged

Avoid TestContext write string allocations#10105
Evangelink merged 2 commits into
mainfrom
dev/amauryleve/fix-testcontext-write-allocation

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Summary

Avoid calling string.Replace in TestContext.Write and WriteLine when the input contains no null characters. The new helper returns the original string in the common case and preserves the existing escaping behavior when null characters are present.

Fixes #10095

Testing

  • Built MSTestAdapter.PlatformServices.UnitTests for net8.0
  • Passed all 927 MSTestAdapter.PlatformServices.UnitTests tests

Skip null-character replacement when the input contains no null characters.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: abd02d85-66b7-43e1-b3ac-b08419abb848
Copilot AI review requested due to automatic review settings July 21, 2026 07:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Optimizes null-character escaping in TestContext.Write and WriteLine.

Changes:

  • Centralizes escaping in EscapeNullChars.
  • Adds a pre-check before replacement.
Show a summary per file
File Description
TestContextImplementation.cs Updates four write paths to use the helper.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment thread src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.cs Outdated

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

Review Summary

Verdict: Looks good

This is a clean, focused performance optimization. The new EscapeNullChars helper avoids the Replace allocation when no null characters are present (the common case). The [return: NotNullIfNotNull] annotation preserves nullability flow.

All 22 dimensions checked — no issues found. The change is minimal, correct, and well-structured.

@Evangelink Evangelink added the state/needs-review Awaiting review from the team. label Jul 21, 2026
@Evangelink
Evangelink enabled auto-merge (squash) July 21, 2026 10:56
Copilot AI review requested due to automatic review settings July 21, 2026 10:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

@Evangelink
Evangelink merged commit 921d95e into main Jul 21, 2026
25 of 27 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/fix-testcontext-write-allocation branch July 21, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[efficiency-improver] Avoid string allocation in TestContext.Write/WriteLine when no null chars present

3 participants