r2mods/ilspy_dump/ror2_csproj/MemoizedToString.cs

40 lines
868 B
C#
Raw Normal View History

2024-10-04 07:26:37 +00:00
using System;
public struct MemoizedToString<TInput, TToString> where TInput : IEquatable<TInput> where TToString : struct, IToStringImplementation<TInput>
{
private TInput lastInput;
private string lastOutput;
private TToString implementation;
private static readonly MemoizedToString<TInput, TToString> defaultValue;
public string GetString(in TInput input)
{
if (!input.Equals(lastInput))
{
lastInput = input;
lastOutput = implementation.DoToString(in lastInput);
}
return lastOutput;
}
public static MemoizedToString<TInput, TToString> GetNew()
{
return defaultValue;
}
static MemoizedToString()
{
TInput input = default(TInput);
TToString val = default(TToString);
defaultValue = new MemoizedToString<TInput, TToString>
{
lastInput = input,
lastOutput = val.DoToString(in input),
implementation = val
};
}
}