Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various refactorings and optimizations #494

Merged
merged 7 commits into from
Oct 21, 2017
Merged

Various refactorings and optimizations #494

merged 7 commits into from
Oct 21, 2017

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Oct 21, 2017

No description provided.

This commit removes the `CurrentInterceptContext` class, which was
apparently introduced so that `ExtractProxyCall` and `ExecuteCall`
could share data. This need indicates that these two strategies per-
haps shouldn't be two separate strategies in the first place; one
identifies a setup, and the other then executes it.

The solution here is to merge the two interception strategies into
one, thereby rendering `CurrentInterceptContext` obsolete.

(Even after this, there are cases where interception strategies de-
pend on one another; the correct working of Moq relies on them being
called in a specific order. Ideally, interception strategies would be
totally independent of one another, each one having a distinct res-
ponsibility. This might be improved upon at a later time.)
Copy link
Contributor Author

@stakx stakx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding some explanations for the various changes made, in case anyone ever ends up looking at these commits.


namespace Moq
{
internal sealed class Condition
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously hidden in a different file.

@@ -259,31 +259,5 @@ internal class CallInfo
public MethodInfo Method { get; set; }
public IEnumerable<Expression> Arguments { get; set; }
}

internal sealed class RemoveMatcherConvertVisitor : ExpressionVisitor
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead code, not used anywhere.

}
}

IProxyCall matchedSetup = lastMatchingSetupForSameMethod ?? lastMatchingSetup;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matchedSetup essentially takes the place of the redundant CurrentInterceptContext class.

@@ -101,52 +125,11 @@ private static void ThrowIfReturnValueRequired(IProxyCall call, ICallContext inv
}
}

internal class ExtractProxyCall : IInterceptStrategy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged with ExtractProxyCall into ExtractAndExecuteProxyCall.

if (!IsObjectMethod(method))
{
return InterceptionAction.Continue;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New fast path. There's no reason why we should perform this check 3 times as we did up until now.

@@ -340,20 +309,20 @@ public ICallbackResult Callback(Delegate callback)

protected virtual void SetCallbackWithoutArguments(Action callback)
{
this.setupCallback = delegate { callback(); };
this.callbackResponse = (object[] args) => callback();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I first read that code, I was wondering why old-style delegate was used here. Make the lambda parameter explicit so it's clear exactly what is going on here, and also to make this method look more similar to SetCallbackWithArguments (below).

}
else
{
this.raiseEventResponse = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should possibly throw instead, like Callback does when given a null argument.

}
else
{
this.raiseEventResponse = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, this should possibly throw instead, like Callback does when given a null argument.

var targetTypeName = lambda.Parameters[0].Type.Name;

message.Append(targetTypeName).Append(" ").Append(lambda.ToStringFixed());

if (TestMethod != null && FileName != null && FileLine != 0)
#if !NETCORE
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the fields are removed when targeting .NET Core, we need this directive to completely omit this piece of code.

@@ -478,34 +463,57 @@ public string Format()

return builder.ToString();
}
}

internal class Condition
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into its own file.

@stakx stakx merged commit 405b9c8 into devlooped:develop Oct 21, 2017
@stakx stakx deleted the diet branch October 21, 2017 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant