-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Implement IUtf8SpanFormattable on DateTime, DateTimeOffset, DateOnly, TimeOnly, TimeSpan, Char, Rune #84469
Conversation
… TimeOnly, TimeSpan, Char, Rune
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsContributes to #81500 (Note that we have a fair amount of code duplication between various formatters (like the DateTimeFormat helper updated in this PR), FormattingHelpers used by Utf8Formatter, and Number.Formatting.cs used by formatting for our primitives. I've done a little consolidation in this PR, but there's a lot more than can / should be done. We're also inconsistent as to whether we're working in terms of spans, refs, or pointers, which leads to more duplication. That can also be consolidated further subsequently.)
|
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ValueListBuilder.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs
Outdated
Show resolved
Hide resolved
Also dedup Utf8Formatter for TimeSpan with TimeSpan's new IUtf8SpanFormattable implementation and a little more cleanup. And fix parameter name of TryFormat to match approved name.
private DateTime _dt = new DateTime(2023, 04, 06, 10, 37, 12, DateTimeKind.Utc);
private TimeSpan _ts = TimeSpan.FromSeconds(12345.6789);
private char[] _chars = new char[100];
private byte[] _bytes = new byte[100];
[Benchmark] public bool DT_Char_R() => _dt.TryFormat(_chars, out _, "r");
[Benchmark] public bool DT_Char_O() => _dt.TryFormat(_chars, out _, "o");
[Benchmark] public bool DT_Char_Rfc1123() => _dt.TryFormat(_chars, out _, DateTimeFormatInfo.InvariantInfo.RFC1123Pattern);
[Benchmark] public bool TS_Char_C() => _ts.TryFormat(_chars, out _, "c");
[Benchmark] public bool TS_Char_G() => _ts.TryFormat(_chars, out _, "G");
[Benchmark] public bool UTF8Formatter_DT_R() => Utf8Formatter.TryFormat(_dt, _bytes, out _, new StandardFormat('R'));
[Benchmark] public bool UTF8Formatter_DT_O() => Utf8Formatter.TryFormat(_dt, _bytes, out _, new StandardFormat('O'));
[Benchmark] public bool UTF8Formatter_TS_C() => Utf8Formatter.TryFormat(_ts, _bytes, out _, default);
[Benchmark] public bool UTF8Formatter_TS_G() => Utf8Formatter.TryFormat(_ts, _bytes, out _, new StandardFormat('G'));
|
Contributes to #81500
(Note that we have a fair amount of code duplication between various formatters (like the DateTimeFormat helper updated in this PR), FormattingHelpers used by Utf8Formatter, and Number.Formatting.cs used by formatting for our primitives. I've done a little consolidation in this PR, but there's a lot more than can / should be done. We're also inconsistent as to whether we're working in terms of spans, refs, or pointers, which leads to more duplication. That can also be consolidated further subsequently.)