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.Intrinsics.Arm; | |
namespace System.Runtime.Instrinsics; | |
public static class VectorExtensions | |
{ | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
internal static int CountMatches<T>(this Vector256<T> mask) | |
{ |
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 Microsoft.AspNetCore.StaticFiles.Infrastructure; | |
using Microsoft.Extensions.FileProviders; | |
var builder = WebApplication.CreateBuilder(args); | |
// builder.Logging.SetMinimumLevel(LogLevel.Warning); | |
builder.Services | |
.AddAntiforgery() | |
.AddResponseCompression(); |
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
// Proposal: https://github.com/dotnet/runtime/issues/75317 | |
// This code is licensed under MIT license | |
// (c) 2022 neon-sunset | |
using System.Runtime.CompilerServices; | |
namespace System; | |
public static class SplitExtensions | |
{ |
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
// This code is licensed under MIT license | |
// (c) 2022-2023 neon-sunset | |
using System.Buffers; | |
using System.Diagnostics.CodeAnalysis; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
[StructLayout(LayoutKind.Auto)] |
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
#pragma warning disable IL2026 | |
using FastCache; | |
using Markdig; | |
using Microsoft.AspNetCore.Mvc; | |
using NonBlocking; | |
var builder = WebApplication.CreateBuilder(); | |
builder.Services.AddHttpClient(); | |
var app = builder.Build(); |
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.Diagnostics; | |
// Set your own execution time here. | |
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)); | |
// dotnet add package RangeExtensions | |
// Feel free to spawn an arbitrary (within reason) count of workers to simulate desired concurrency. | |
// Keep in mind that HttpClient might reuse HttpMessageHandler's, feel free to tune to your taste. | |
var workers = (..64) // ..Environment.ProcessorCount is also a good idea for simpler cases. | |
.AsEnumerable() |
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 Cysharp.Collections; // dotnet add package NativeMemoryArray | |
namespace BufferAllocExample; | |
public static class ExampleBufferedBytesProcessor | |
{ | |
public static int ProcessBytes(IUtf8Processor processor, ReadOnlySpan<char> source, Span<byte> destination) | |
{ | |
const int StackAllocLimit = 1024; // 1KB | |
const int ArrayPoolLimit = 1024 * 1024 * 10; // 10MB |
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.InteropServices; | |
var writeable = MemoryMarshal | |
.AsMemory(false.ToString().AsMemory()) | |
.Span; | |
"True\0".CopyTo(writeable); | |
Console.WriteLine((object)false); // Prints 'True' |
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
dotnet publish -c release -f net7.0 -r {RID} -p:PublishSingleFile=true --self-contained true |
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 static class AsyncEnumerableExtensions | |
{ | |
/// <summary> | |
/// Will skip faulted tasks by default | |
/// </summary> | |
public static async IAsyncEnumerable<TResult?> ParallelSelectAsync<T, TResult>( | |
this IEnumerable<T> items, | |
Func<T, Task<TResult>> operation, | |
int parallelism = -1, | |
bool throwOnError = false) |