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
[StructLayout(LayoutKind.Sequential, Size = 1)] | |
internal struct BitBool | |
{ | |
byte value; // = 0b00000000; | |
public bool IsZero | |
{ | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
get => value == 0; | |
} |
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.Net; | |
using System.Net.Http; | |
using System.Runtime.CompilerServices; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using UnityEngine; | |
using UnityEngine.Networking; |
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
[StructLayout(LayoutKind.Auto)] | |
internal struct CompactListCore<T> | |
where T : class | |
{ | |
const double ShrinkRate = 0.8; | |
const int InitialArraySize = 4; | |
const int MinShrinkStartSize = 16; | |
readonly object gate; | |
T?[]? values = null; |
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.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
using System.Text.Json; | |
namespace ZLogger.Internal; | |
internal sealed class EnumDictionary | |
{ | |
readonly Entry[][] buckets; // immutable array. |
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
//<Project Sdk="Microsoft.NET.Sdk"> | |
// <PropertyGroup> | |
// <OutputType>Exe</OutputType> | |
// <TargetFramework>net6.0</TargetFramework> | |
// <ImplicitUsings>enable</ImplicitUsings> | |
// <Nullable>enable</Nullable> | |
// </PropertyGroup> | |
// <ItemGroup> | |
// <PackageReference Include="BenchmarkDotNet" Version="0.13.2" /> | |
// <PackageReference Include="MessagePack" Version="2.4.35" /> |
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 async Task SendAsync(CancellationToken cancellationToken = default) | |
{ | |
var timeoutTokenSource = timeoutTokenSourcePool.Get(); | |
CancellationTokenRegistration externalCancellation = default; | |
if (cancellationToken.CanBeCanceled) | |
{ | |
externalCancellation = cancellationToken.UnsafeRegister(static state => | |
{ | |
((CancellationTokenSource)state!).Cancel(); |
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
class Client : IDisposable | |
{ | |
readonly TimeSpan timeout; | |
readonly ObjectPool<CancellationTokenSource> timeoutTokenSourcePool; | |
readonly CancellationTokenSource clientLifetimeTokenSource; | |
public TimeSpan Timeout { get; } | |
public Client(TimeSpan timeout) | |
{ |
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 async Task SendAsync(CancellationToken cancellationToken = default) | |
{ | |
var timeoutTokenSource = timeoutTokenSourcePool.Get(); | |
CancellationTokenRegistration externalCancellation = default; | |
if (cancellationToken.CanBeCanceled) | |
{ | |
// When raised argument CancellationToken, raise Timeout's CancellationToken | |
externalCancellation = cancellationToken.UnsafeRegister(static state => | |
{ |
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
class Client | |
{ | |
// For classes that prohibit multiple calls to methods such as SqlConnection, add a single CancellationTokenSource to the field | |
// Things like HttpClient, which may be called multiple times, are held in ObjectPool. | |
readonly ObjectPool<CancellationTokenSource> timeoutTokenSourcePool; | |
public TimeSpan Timeout { get; } | |
public Client(TimeSpan timeout) |
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 async Task SendAsync(CancellationToken cancellationToken = default) | |
{ | |
using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); | |
cts.CancelAfter(Timeout); | |
try | |
{ | |
await SendCoreAsync(cts.Token); | |
} | |
catch (OperationCanceledException ex) when (ex.CancellationToken == cts.Token) |
NewerOlder