Skip to content

Instantly share code, notes, and snippets.

Nobuyuki Iwanaga ufcpp

Block or report user

Report or block ufcpp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ufcpp
ufcpp / TimeBenchmark.cs
Last active Aug 23, 2019
やっぱ UtcNow の方が速いんだ。的なやつ。
View TimeBenchmark.cs
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
public class TimeBenchmark
{
[Benchmark]
public long DateTimeNowTicks() => DateTime.Now.Ticks;
[Benchmark]
public long DateTimeUtcNowTicks() => DateTime.UtcNow.Ticks;
@ufcpp
ufcpp / BidiClass.cs
Created Aug 16, 2019
コンパイル時動的メモリ確保(non transient)が欲しい気持ちわからなくもない感じのだいぶやらかしたコード
View BidiClass.cs
using System;
using System.Runtime.InteropServices;
class Program
{
static void Main()
{
var s = "a àαаאاああ゙한亜ก\n";
foreach (var c in s)
@ufcpp
ufcpp / NrtVs16_3_p2.cs
Last active Aug 14, 2019
16.3 Preview 2 時点でいくつか確認
View NrtVs16_3_p2.cs
using System;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
class Program
{
static void Main()
{
string? s1 = NullIfEmpty<string>(null); // 意図通り警告
@ufcpp
ufcpp / MutateString.cs
Last active Aug 6, 2019
string を書き換え可能な一時バッファーとして使う
View MutateString.cs
using System;
public class Program
{
static void Main()
{
const int BufferLength = 256;
// string を書き換え可能な一時バッファーとして使う。
// 普通は new char[] とか stackalloc char[] を使えばこんな邪悪な真似しなくていいんだけど、string しか受け付けない API を何ループも呼び出す必要がありそうで…
@ufcpp
ufcpp / NullRef.cs
Created Aug 2, 2019
safe な C# ではありえないはずの null 参照
View NullRef.cs
using System;
using System.Runtime.CompilerServices;
public class Program
{
// safe な C# ではありえないはずの null 参照。
// だいぶ邪悪。
private unsafe static ref T NullRef<T>() => ref Unsafe.AsRef<T>(null);
private unsafe static bool IsNull<T>(ref T x) => Unsafe.AsPointer(ref x) == null;
@ufcpp
ufcpp / u_getNumericValue.cs
Created Jul 28, 2019
ICU の u_getNumericValue 呼び出し
View u_getNumericValue.cs
using System;
using System.Runtime.InteropServices;
public class Program
{
[DllImport("icuuc.dll")]
public static extern double u_getNumericValue(int c);
static void Main()
{
@ufcpp
ufcpp / vs16_2_p3.cs
Created Jun 26, 2019
Visual Studio 16.2 Preview 3 がらみ
View vs16_2_p3.cs
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
// notnull 制約は 16.2.P3 から対応してそう。
// ただ、Visual Studio 上ではコード補完、ハイライト効いてない。
class C<T>
where T : notnull
{
public T Value { get; }
View ParseNumber.cs
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.Linq;
using System.Runtime.CompilerServices;
public class Program
{
private const byte X = 0xff;
private static ReadOnlySpan<byte> DigitTableROS => new byte[] { X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, X, X, X, X, X, X, X, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, X, X, X, X, X, X, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, X, X, X, X, X, };
@ufcpp
ufcpp / WhiteNoise.cs
Created Jun 20, 2019
平均0の一様乱数で作った数列は自己相関関数がδ関数になる
View WhiteNoise.cs
using System;
using System.Linq;
class Program
{
static void Main()
{
const int N = 1 << 10;
const int Mask = N - 1;
@ufcpp
ufcpp / DimReabstraction.cs
Created Jun 13, 2019
Visual Studio 16.2 Preview 2 から実装入ってそう
View DimReabstraction.cs
using System;
interface A
{
void M() => Console.WriteLine("default implementation");
}
interface B : A
{
abstract void A.M();
You can’t perform that action at this time.