public static void Main(string[] args) { var summary = BenchmarkRunner.Run <IntroBenchmarkBaseline>(); Console.WriteLine("Result: {0}", SimpleCaseFolding.SimpleCaseFold("cASEfOLDING2")); Console.WriteLine("Result: {0}", SimpleCaseFolding.SimpleCaseFold("яЯяЯяЯяЯяЯя2")); }
private static int GetHashCodeSimpleCaseFolding(string source) { Debug.Assert(source != null, "source must not be null"); // Do not allocate on the stack if string is empty if (source.Length == 0) { return(source.GetHashCode()); } char[] borrowedArr = null; Span <char> destination = source.Length <= 255 ? stackalloc char[source.Length] : (borrowedArr = ArrayPool <char> .Shared.Rent(source.Length)); SimpleCaseFolding.SimpleCaseFold(source, destination); int hash = String.GetHashCode(destination); // Return the borrowed array if necessary. if (borrowedArr != null) { ArrayPool <char> .Shared.Return(borrowedArr); } return(hash); }
private static unsafe int ComputeHash32OrdinalIgnoreCaseSlow(ref char data, int count, uint p0, uint p1) { Debug.Assert(count > 0); char[] borrowedArr = null; Span <char> scratch = (uint)count <= 64 ? stackalloc char[64] : (borrowedArr = ArrayPool <char> .Shared.Rent(count)); SimpleCaseFolding.SimpleCaseFold(new ReadOnlySpan <char>(Unsafe.AsPointer(ref data), count), scratch); // Slice the array to the size returned by ToUpperInvariant. // Multiplication below may overflow, that's fine since it's going to an unsigned integer. int hash = ComputeHash32(ref Unsafe.As <char, byte>(ref MemoryMarshal.GetReference(scratch)), count * 2, p0, p1); // Return the borrowed array if necessary. if (borrowedArr != null) { ArrayPool <char> .Shared.Return(borrowedArr); } return(hash); }
public char FixedCharFold(char c) { return(SimpleCaseFolding.SimpleCaseFold(c)); }
public string SimpleCaseFold(string StrA) { return(SimpleCaseFolding.SimpleCaseFold(StrA)); }
public char SimpleCaseFold() { return(SimpleCaseFolding.SimpleCaseFold(TestChar)); }