Skip to content

Instantly share code, notes, and snippets.

View vanbukin's full-sized avatar

Roman Bukin vanbukin

View GitHub Profile
@vanbukin
vanbukin / Types.cs
Last active May 18, 2019 15:35
Fast UUIDv1
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Dodo.Types
{
[StructLayout(LayoutKind.Sequential, Size = 16, CharSet = CharSet.Ansi, Pack = 1)]
public struct Uuidv1
{
static Uuidv1()
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Uuid1
{
public struct Uuidv1 : IFormattable
{
static Uuidv1()
@vanbukin
vanbukin / Uuid.cs
Last active August 28, 2019 23:00
Uuidv1_29_08_2019_rev1
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Uuid1
{
public unsafe struct Uuidv1 : IFormattable
{
static Uuidv1()
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Uuid1
{
public unsafe struct Uuidv1 : IFormattable
{
static Uuidv1()
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Uuid1
{
[StructLayout(LayoutKind.Explicit, Pack = 1)]
[SuppressMessage("ReSharper", "InconsistentNaming")]
@vanbukin
vanbukin / HttpCallException.cs
Last active September 6, 2019 06:50
HttpExtensinos
using System;
namespace Infrastructure.ApiClients.Http
{
public class HttpCallException : Exception
{
public HttpCallException(int? statusCode, string message) : base(message)
{
StatusCode = statusCode;
}
@vanbukin
vanbukin / CoreLibInternal.cs
Last active January 1, 2020 16:44
Uuid Interop
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
[assembly:IgnoresAccessChecksTo("System.Private.CoreLib")]
namespace Uuid.CoreLib
{
public static class Internal
{
public static unsafe void GetRandomBytes(byte* buffer, int length)
@vanbukin
vanbukin / Program.cs
Created February 24, 2020 03:31
GuidBenchmarks - MemoryMarshal remove
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace GuidBenchmarks
{
public static class Program
{
public static void Main(string[] args)
private unsafe void FormatD(char* dest)
{
// dddddddd-dddd-dddd-dddd-dddddddddddd
uint* destUints = (uint*)dest;
char** destUintsAsChars = (char**)&destUints;
uint* tableToHex = TableToHex;
dest[8] = dest[13] = dest[18] = dest[23] = '-';
destUints[0] = tableToHex[(byte)(_a >> 24)];
destUints[1] = tableToHex[(byte)(_a >> 16)];
public unsafe partial struct Uuid
{
public string ToStringWithStringCreate(string? format, IFormatProvider? formatProvider)
{
// ... same as original ToString
var uuidString = string.Create(32, this, (span, state) =>
{
fixed (char* uuidChars = &span.GetPinnableReference())
{
FormatNThis(state, uuidChars);