use switch rather than dict lookup
This commit is contained in:
parent
f9f2f5b81a
commit
fad93a7973
|
|
@ -1,5 +1,4 @@
|
||||||
using Qrakhen.Qamp.Core.Collections;
|
using Qrakhen.Qamp.Core.Collections;
|
||||||
using Qrakhen.Qamp.Core.Compilation;
|
|
||||||
using Qrakhen.Qamp.Core.Logging;
|
using Qrakhen.Qamp.Core.Logging;
|
||||||
using Qrakhen.Qamp.Core.Values;
|
using Qrakhen.Qamp.Core.Values;
|
||||||
|
|
||||||
|
|
@ -20,28 +19,49 @@ public static class ValueOperation
|
||||||
#if LOG
|
#if LOG
|
||||||
_logger.Method($"{operation.Left} {operation.OpCode} {operation.Right}");
|
_logger.Method($"{operation.Left} {operation.OpCode} {operation.Right}");
|
||||||
#endif
|
#endif
|
||||||
return _operations[operation.OpCode].Invoke(operation);
|
|
||||||
|
// p sure switch is faster here (as opposed to dict lookup)
|
||||||
|
return operation.OpCode switch {
|
||||||
|
OpCode.Equal => Equal(operation),
|
||||||
|
OpCode.Greater => Greater(operation),
|
||||||
|
OpCode.Less => Less(operation),
|
||||||
|
OpCode.Not => Not(operation),
|
||||||
|
OpCode.Add => Add(operation),
|
||||||
|
OpCode.Subtract => Subtract(operation),
|
||||||
|
OpCode.Divide => Divide(operation),
|
||||||
|
OpCode.Modulo => Modulo(operation),
|
||||||
|
OpCode.Multiply => Multiply(operation),
|
||||||
|
OpCode.Negate => Negate(operation),
|
||||||
|
OpCode.BitwiseOr => BitwiseOr(operation),
|
||||||
|
OpCode.BitwiseAnd => BitwiseAnd(operation),
|
||||||
|
OpCode.BitwiseLeft => BitwiseLeft(operation),
|
||||||
|
OpCode.BitwiseRight => BitwiseRight(operation),
|
||||||
|
OpCode.BitwiseNot => BitwiseInvert(operation),
|
||||||
|
OpCode.BitwiseXor => BitwiseXor(operation),
|
||||||
|
_ => throw new NotImplementedException($"Unknown operator {operation.OpCode}.")
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ValueOperation()
|
static ValueOperation()
|
||||||
{
|
{
|
||||||
_operations = new Register<OpCode, OperationHandler>();
|
_operations = new Register<OpCode, OperationHandler> {
|
||||||
_operations.Add(OpCode.Equal, Equal);
|
{ OpCode.Equal, Equal },
|
||||||
_operations.Add(OpCode.Greater, Greater);
|
{ OpCode.Greater, Greater },
|
||||||
_operations.Add(OpCode.Less, Less);
|
{ OpCode.Less, Less },
|
||||||
_operations.Add(OpCode.Not, Not);
|
{ OpCode.Not, Not },
|
||||||
_operations.Add(OpCode.Add, Add);
|
{ OpCode.Add, Add },
|
||||||
_operations.Add(OpCode.Subtract, Subtract);
|
{ OpCode.Subtract, Subtract },
|
||||||
_operations.Add(OpCode.Divide, Divide);
|
{ OpCode.Divide, Divide },
|
||||||
_operations.Add(OpCode.Modulo, Modulo);
|
{ OpCode.Modulo, Modulo },
|
||||||
_operations.Add(OpCode.Multiply, Multiply);
|
{ OpCode.Multiply, Multiply },
|
||||||
_operations.Add(OpCode.Negate, Negate);
|
{ OpCode.Negate, Negate },
|
||||||
_operations.Add(OpCode.BitwiseOr, BitwiseOr);
|
{ OpCode.BitwiseOr, BitwiseOr },
|
||||||
_operations.Add(OpCode.BitwiseAnd, BitwiseAnd);
|
{ OpCode.BitwiseAnd, BitwiseAnd },
|
||||||
_operations.Add(OpCode.BitwiseLeft, BitwiseLeft);
|
{ OpCode.BitwiseLeft, BitwiseLeft },
|
||||||
_operations.Add(OpCode.BitwiseRight, BitwiseRight);
|
{ OpCode.BitwiseRight, BitwiseRight },
|
||||||
_operations.Add(OpCode.BitwiseNot, BitwiseInvert);
|
{ OpCode.BitwiseNot, BitwiseInvert },
|
||||||
_operations.Add(OpCode.BitwiseXor, BitwiseXor);
|
{ OpCode.BitwiseXor, BitwiseXor }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Value Equal(Operation operation)
|
public static Value Equal(Operation operation)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue