ufcpp-live / UfcppLiveAgenda

@ufcpp live streaming agenda
MIT License
24 stars 2 forks source link

.NET 9 Preview 6 / Visual Studio 17.11 Preview 3 #92

Open ufcpp opened 1 month ago

ufcpp commented 1 month ago

配信URL: https://www.youtube.com/live/yiy1WAlFwag

C

Extensions は C# 13 から外れる。

まあ、このタイミングで Unsafe.As 使う路線がダメだとなったら、今更 C# 13 に間に合うはずもなく。 https://x.com/ufcpp/status/1803261091046367443

今回、partial プロパティ追加。

partial class A
{
    public partial int X { get; }
}
partial class A
{
    public partial int X => 0;
}

GeneratedRegex がメソッドにしかつけれないのだいぶ残念だったし。

partial class A
{
    [GeneratedRegex(@"\d+")]
    public static partial Regex X { get; }
}

ライブラリ

ランタイム

Loop Optimizations とか面白そう

ufcpp-live commented 1 month ago
class A
{
    Dictionary<int, int> d;

    // IEnumerable 介すると遅いんでこんなことに…
    public Dictionary<int, int>.KeyCollection Keys => d.Keys;

    // なので ReadOnlyDictionary (IDictionary を受け取る)は論外に…
}
ufcpp-live commented 1 month ago
using System.Runtime.InteropServices;

string[] data = ["a", "b", "ab", "bc", "abc"];
var q = data.GroupBy(x => x.Length).Sum(x => x.Count());

Dictionary<int, int> d = [];

foreach (var x in data)
{
    ref var r = ref CollectionsMarshal.GetValueRefOrAddDefault(d, x.Length, out _);
    r++;
}

Span<int> d1 = stackalloc int[4];

foreach (var x in data)
{
    ref var r = ref d1[x.Length];
    r++;
}
ufcpp-live commented 1 month ago
Span<byte> x = stackalloc byte[0];
Console.WriteLine(x.Length);
Console.WriteLine(x == default); // true だった。 stackalloc 0 は null ポインターくさい。
ufcpp-live commented 1 month ago
var a1 = (Span<int> x) => 1;
Console.WriteLine(a1.GetType().Name); // Func`2 になった

var a2 = (ref int x) => 1;
Console.WriteLine(a2.GetType().Name); // 匿名型
ufcpp-live commented 1 month ago

image

ufcpp-live commented 1 month ago
Dictionary<string, int> d = new(StringComparer.Ordinal) { { "key", 1 } };

// UTF-8 比較版が欲しければ、
// StringComparer.Ordinal のところを自作必要あり。
// IAlternateEqualityComparer<ReadOnlySpan<byte>, string> 実装が必要。
var alt = d.GetAlternateLookup<string, int, ReadOnlySpan<byte>>();

alt.TryGetValue("key"u8, out var value);

Console.WriteLine(value);
ufcpp-live commented 1 month ago

image