Optimize GC for PropOp.Enum<T>.
This commit is contained in:
@@ -72,19 +72,21 @@ namespace Cryville.Crtr {
|
||||
public class Enum<T> : PropOp {
|
||||
readonly static Dictionary<int, int> _cache = new Dictionary<int, int>();
|
||||
readonly Action<T> _cb;
|
||||
public Enum(Action<T> cb) {
|
||||
readonly Func<int, T> _caster;
|
||||
public Enum(Action<T> cb, Func<int, T> caster) {
|
||||
if (!typeof(T).IsEnum)
|
||||
throw new ArgumentException("Type is not enum");
|
||||
var names = typeof(T).GetFields(BindingFlags.Public | BindingFlags.Static);
|
||||
for (int i = 0; i < names.Length; i++)
|
||||
_cache[IdentifierManager.SharedInstance.Request(names[i].Name)] = Convert.ToInt32(names[i].GetValue(null));
|
||||
_cb = cb;
|
||||
_caster = caster;
|
||||
}
|
||||
protected override void Execute() {
|
||||
int result = 0;
|
||||
for (int i = 0; i < LoadedOperandCount; i++)
|
||||
result |= _cache[GetOperand(0).AsIdentifier()];
|
||||
_cb((T)(object)result);
|
||||
_cb(_caster(result));
|
||||
}
|
||||
}
|
||||
public class BeatTime : PropOp {
|
||||
|
Reference in New Issue
Block a user