Skip to content

Commit

Permalink
Use MehtodHandle.Value. Changed the _operationMap to be Dictionary<In…
Browse files Browse the repository at this point in the history
…tPtr, string> to avoid boxing.
  • Loading branch information
mchlstrng authored and mconnew committed May 23, 2022
1 parent 0a4daa7 commit ea9d0a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ void IContractBehavior.ApplyClientBehavior(ContractDescription description, Serv

internal class MethodInfoOperationSelector : IClientOperationSelector
{
private Dictionary<object, string> _operationMap;
private Dictionary<IntPtr, string> _operationMap;

internal MethodInfoOperationSelector(ContractDescription description, MessageDirection directionThatRequiresClientOpSelection)
{
_operationMap = new Dictionary<object, string>();
_operationMap = new Dictionary<IntPtr, string>();

for (int i = 0; i < description.Operations.Count; i++)
{
Expand All @@ -48,26 +48,26 @@ internal MethodInfoOperationSelector(ContractDescription description, MessageDir
{
if (operation.SyncMethod != null)
{
if (!_operationMap.ContainsKey(operation.SyncMethod))
if (!_operationMap.ContainsKey(operation.SyncMethod.MethodHandle.Value))
{
_operationMap.Add(operation.SyncMethod, operation.Name);
_operationMap.Add(operation.SyncMethod.MethodHandle.Value, operation.Name);
}
}

if (operation.BeginMethod != null)
{
if (!_operationMap.ContainsKey(operation.BeginMethod))
if (!_operationMap.ContainsKey(operation.BeginMethod.MethodHandle.Value))
{
_operationMap.Add(operation.BeginMethod, operation.Name);
_operationMap.Add(operation.EndMethod, operation.Name);
_operationMap.Add(operation.BeginMethod.MethodHandle.Value, operation.Name);
_operationMap.Add(operation.EndMethod.MethodHandle.Value, operation.Name);
}
}

if (operation.TaskMethod != null)
{
if (!_operationMap.ContainsKey(operation.TaskMethod))
if (!_operationMap.ContainsKey(operation.TaskMethod.MethodHandle.Value))
{
_operationMap.Add(operation.TaskMethod, operation.Name);
_operationMap.Add(operation.TaskMethod.MethodHandle.Value, operation.Name);
}
}
}
Expand All @@ -81,9 +81,9 @@ public bool AreParametersRequiredForSelection

public string SelectOperation(MethodBase method, object[] parameters)
{
if (_operationMap.ContainsKey(method))
if (_operationMap.ContainsKey(method.MethodHandle.Value))
{
return _operationMap[method];
return _operationMap[method.MethodHandle.Value];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ internal bool IsSyncCall(MethodCall methodCall)

Contract.Assert(methodCall != null);
Contract.Assert(methodCall.MethodBase != null);
return methodCall.MethodBase.Equals(_syncMethod);
return methodCall.MethodBase.MethodHandle.Value.Equals(_syncMethod.MethodHandle.Value);
}

internal bool IsBeginCall(MethodCall methodCall)
Expand All @@ -269,7 +269,7 @@ internal bool IsBeginCall(MethodCall methodCall)

Contract.Assert(methodCall != null);
Contract.Assert(methodCall.MethodBase != null);
return methodCall.MethodBase.Equals(_beginMethod);
return methodCall.MethodBase.MethodHandle.Value.Equals(_beginMethod.MethodHandle.Value);
}

internal bool IsTaskCall(MethodCall methodCall)
Expand All @@ -281,7 +281,7 @@ internal bool IsTaskCall(MethodCall methodCall)

Contract.Assert(methodCall != null);
Contract.Assert(methodCall.MethodBase != null);
return methodCall.MethodBase.Equals(_taskMethod);
return methodCall.MethodBase.MethodHandle.Value.Equals(_taskMethod.MethodHandle.Value);
}

internal object[] MapSyncInputs(MethodCall methodCall, out object[] outs)
Expand Down

0 comments on commit ea9d0a9

Please sign in to comment.