Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Safe code] Clean up Guid.TryFormatX #110923

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Dec 24, 2024

Contributes to #94941

This PR removes unsafe code from Guid.TryFormatX + small clean up in TryParseExact.

New version is 10-15% faster.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 24, 2024
@EgorBo

This comment was marked as resolved.

@EgorBo
Copy link
Member Author

EgorBo commented Dec 24, 2024

@EgorBot -amd -arm -profiler

using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;

public class Benchmark
{
    static Guid guid = Guid.Parse("{D420C46B-04DC-4ABD-BF32-5132E82EE7F7}");

    [Benchmark]
    public bool FormatX()
    {
        Span<char> buffer = stackalloc char[100];
        bool result = guid.TryFormat(buffer, out int charsWritten, "X");
        Consume(buffer.Slice(0, charsWritten));
        return result;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Consume(Span<char> _){}
}

@jkotas jkotas added area-System.Runtime and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Dec 24, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

@EgorBo

This comment was marked as resolved.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants