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
using System; | |
using System.IO; | |
using System.Reflection; | |
using System.Runtime.InteropServices; | |
using static System.Console; | |
namespace versioninfo | |
{ | |
class Program | |
{ |
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
static double ParseJson() | |
{ | |
const string json = " [ { \"name\": \"John\" }, [ \"425-000-1212\", 15 ], { \"grades\": [ 90, 80, 100, 75 ] } ]"; | |
double average = -1; | |
using (JsonDocument doc = JsonDocument.Parse(json)) | |
{ | |
JsonElement root = doc.RootElement; | |
JsonElement info = root[1]; |
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
public class ArrayBufferWriter : IBufferWriter<byte>, IDisposable | |
{ | |
private byte[] _rentedBuffer; | |
private int _written; | |
public ArrayBufferWriter(int initialCapacity) | |
{ | |
// TODO: argument validation | |
_rentedBuffer = ArrayPool<byte>.Shared.Rent(initialCapacity); |
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
static int WriteJson(IBufferWriter<byte> output, long[] extraData) | |
{ | |
var json = new Utf8JsonWriter(output, state: default); | |
json.WriteStartObject(); | |
json.WriteNumber("age", 15, escape: false); | |
json.WriteString("date", DateTime.Now); | |
json.WriteString("first", "John"); | |
json.WriteString("last", "Smith"); |
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
Vector256<int> SoftwareFallback(int x) | |
{ | |
var result = Vector256<int>.Zero; | |
((int*)(&result))[0] = x; | |
return result; | |
} |
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
Vector256<short> SoftwareFallback(short x) | |
{ | |
var result = Vector256<short>.Zero; | |
Unsafe.WriteUnaligned(ref Unsafe.As<Vector256<short>, byte>(ref result), value); | |
return result; | |
} | |
// https://github.com/dotnet/coreclr/blob/57fd77e6f8f7f2c37cc5c3b36df3ea4f302e143b/src/System.Private.CoreLib/shared/System/Runtime/Intrinsics/Vector256.cs#L1303 |
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
Vector256<double> SoftwareFallback(double x) | |
{ | |
var pResult = stackalloc double[4] | |
{ | |
x, | |
x, | |
x, | |
x, | |
}; |
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
Vector256<double> SoftwareFallback(double x) | |
{ | |
var pResult = stackalloc double[4] | |
{ | |
x, | |
x, | |
x, | |
x, | |
}; |
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
static State ChangeState(State current, Transition transition, bool hasKey) => | |
(current, transition) switch | |
{ | |
(Opened, Close) => Closed, | |
(Closed, Open) => Opened, | |
(Closed, Lock) when hasKey => Locked, | |
(Locked, Unlock) when hasKey => Closed, | |
_ => throw new InvalidOperationException($"Invalid transition") | |
}; |
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
static string Display(object o) => o switch | |
{ | |
Point { X: 0, Y: 0 } => "origin", | |
Point { X: var x, Y: var y } => $"({x}, {y})", | |
_ => "unknown" | |
}; |