private void TryOptimizeArgument(MsilInstruction instruction)
{
var parameter = instruction.Operand as ParameterSignature;
if (Method == null || Method.Signature == null || parameter == null)
return;
int index = Method.Signature.Parameters.IndexOf(parameter);
if (index < 0 || index > byte.MaxValue)
return;
switch (instruction.OpCode.Code)
{
case MsilCode.Ldarg:
if (index <= 3)
{
instruction.OpCode = MsilOpCodes.SingleByteOpCodes[MsilOpCodes.Ldarg_0.Op2 + index];
instruction.Operand = null;
}
else
{
instruction.OpCode = MsilOpCodes.Ldarg_S;
}
break;
case MsilCode.Ldarga:
instruction.OpCode = MsilOpCodes.Ldarga_S;
break;
}
}