Repository navigation
Avoid allocation when parsing whitespace-free UTF-8 X-format Guids - #135272
Merged
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5d630bcd-7f26-414f-94df-31fe18fb5203
Member
Author
|
@EgorBot -arm using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkSwitcher.FromAssembly(typeof(Bench).Assembly).Run(args);
[MemoryDiagnoser]
public class Bench {
[Benchmark]
public Guid Parse() =>
Guid.Parse("{0x00112233,0x4455,0x6677,{0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff}}"u8);
}Note Benchmark comment generated with GitHub Copilot. |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-runtime |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused correction matches the helper’s intended behavior, with existing tests covering UTF-8 X-format inputs both with and without whitespace.
Review effort: Balanced
Findings: None
What changed in this PR
Corrects UTF-8 X-format GUID whitespace detection, avoiding an unnecessary allocation for canonical inputs.
Changes:
- Stops scanning at the first whitespace rune.
- Preserves the original span when no whitespace exists.
| File | Description |
|---|---|
src/libraries/System.Private.CoreLib/src/System/Guid.cs |
Fixes the inverted whitespace condition. |
Member
Author
|
PTAL @MihaZupan |
Member
Author
|
/ba-g #135283 |
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.
Fix an inverted whitespace check in UTF-8 X-format Guid parsing. The initial scan stops at the first non-whitespace rune, causing whitespace-free input to allocate and copy a temporary byte array.
Stop at the first whitespace rune instead, enabling the existing return-original-span path. For the canonical X-format input, allocations drop from 96 bytes to zero per parse.