Skip to content
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

Interpolated string improvements #355

Closed
6 tasks done
Tracked by #342
ufcpp opened this issue Aug 13, 2021 · 5 comments
Closed
6 tasks done
Tracked by #342

Interpolated string improvements #355

ufcpp opened this issue Aug 13, 2021 · 5 comments
Labels

Comments

@ufcpp
Copy link
Owner

ufcpp commented Aug 13, 2021

https://github.com/dotnet/csharplang/blob/main/proposals/csharp-10.0/improved-interpolated-strings.md
https://gist.github.com/ufcpp/233d33b0220215bb5bdf2a10e8a434bf
https://ufcpp.net/blog/2021/8/net6p7/#interpolated-string
https://github.com/ufcpp/UfcppSample/tree/master/Demo/2021/Csharp10/InterpolatedStrings

https://ufcpp.net/study/csharp/st_string.html#string-interpolation の中に h3 レベルのセクション追加でいいかな。

  • ↑では「.NET 6 でコンパイルするとパフォーマンス改善するよ」だけ書く
    • InterpolatedStringHandlerArgument
    • オーバーロード解決
      • 基本、string よりも handler 優先。ただし基底クラスと拡張メソッドを除く
    • カルチャー指定も FormattableString 辞めて string.Create に変える方がだいぶ速い
    • ↓を作った後「ページを改めて説明する予定」の文面をリンクに差し替え
  • 詳細な仕組み(Handler に求められる条件とか、自作の仕方とか)は [雑記] 別ページ作って書く
@ufcpp ufcpp mentioned this issue Aug 13, 2021
16 tasks
@ufcpp ufcpp added the C# 10.0 label Aug 13, 2021
@ufcpp

This comment has been minimized.

@ufcpp
Copy link
Owner Author

ufcpp commented Sep 3, 2021

@ufcpp
Copy link
Owner Author

ufcpp commented Sep 5, 2021

https://ufcpp.net/study/csharp/st_string.html#csharp10-improvement に「別途ページを改めて」記載入れた。

@ufcpp
Copy link
Owner Author

ufcpp commented Sep 10, 2021

net6.0 でなくても、 System.Runtime.CompilerServices.DefaultInterpolatedStringHandler って名前の型さえあればそれが使われること確認。
Microsoft.Bcl.AsyncInterfaces みたいな「古いランタイム向けの互換ライブラリ」出してくれるかは不明。
https://source.dot.net/#System.Private.CoreLib/DefaultInterpolatedStringHandler.cs,84c5cc23a9bc6ea8 の移植もできなくはなさげ。

諸事情あって ↑ を netstandard2.0 に移植したい場合、

  • System.Memory 参照は必須
  • string.MaxLength → 0x3FFFFFDF に置き換え
  • Math.Clamp → このくらいなら value < min ? min : value > max ? max : value に置き換え
  • string.CopyTo → 間に AsSpan() 挟めばOK
  • new string(Span<char>)Span<char>.ToString() でOK
  • string.GetRawStringDataUnsafe.AsRef(in value.AsSpan().GetPinnableReference())
  • ISpanFormattable → あきらめてこれ関連の if 分丸ごと消す。パフォーマンスが落ちるだけで動作はする
  • null 許容参照型がらみ → ? を消して回るか、NRT 属性自前定義するか

@ufcpp
Copy link
Owner Author

ufcpp commented Sep 23, 2021

@ufcpp ufcpp closed this as completed Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant