Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Cache other references to Array.prototype.filter
  • Loading branch information
fatso83 committed Aug 10, 2017
1 parent 531f872 commit 56ca580
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/sinon/call.js
Expand Up @@ -6,6 +6,7 @@ var functionName = require("./util/core/function-name");
var sinonFormat = require("./util/core/format");
var valueToString = require("./util/core/value-to-string");
var slice = Array.prototype.slice;
var filter = Array.prototype.filter;

function throwYieldError(proxy, text, args) {
var msg = functionName(proxy) + text;
Expand Down Expand Up @@ -131,7 +132,7 @@ var callProto = {

yieldOn: function (thisValue) {
var args = slice.call(this.args);
var yieldFn = args.filter(function (arg) {
var yieldFn = filter.call(args, function (arg) {
return typeof arg === "function";
})[0];

Expand All @@ -148,7 +149,7 @@ var callProto = {

yieldToOn: function (prop, thisValue) {
var args = slice.call(this.args);
var yieldArg = args.filter(function (arg) {
var yieldArg = filter.call(args, function (arg) {
return arg && typeof arg[prop] === "function";
})[0];
var yieldFn = yieldArg && yieldArg[prop];
Expand Down
5 changes: 3 additions & 2 deletions lib/sinon/collection.js
Expand Up @@ -6,7 +6,8 @@ var sinonMock = require("./mock");
var collectOwnMethods = require("./collect-own-methods");
var valueToString = require("./util/core/value-to-string");

var push = [].push;
var push = Array.prototype.push;
var filter = Array.prototype.filter;

function getFakes(fakeCollection) {
if (!fakeCollection.fakes) {
Expand All @@ -18,7 +19,7 @@ function getFakes(fakeCollection) {

function each(fakeCollection, method) {
var fakes = getFakes(fakeCollection);
var matchingFakes = fakes.filter(function (fake) {
var matchingFakes = filter.call(fakes, function (fake) {
return typeof fake[method] === "function";
});

Expand Down
5 changes: 3 additions & 2 deletions lib/sinon/mock.js
Expand Up @@ -8,6 +8,7 @@ var deepEqual = require("./util/core/deep-equal").use(match);
var wrapMethod = require("./util/core/wrap-method");

var push = Array.prototype.push;
var filter = Array.prototype.filter;

function mock(object) {
if (!object || typeof object === "string") {
Expand Down Expand Up @@ -118,13 +119,13 @@ extend(mock, {
var currentArgs = args || [];
var available;

var expectationsWithMatchingArgs = expectations.filter(function (expectation) {
var expectationsWithMatchingArgs = filter.call(expectations, function (expectation) {
var expectedArgs = expectation.expectedArguments || [];

return arrayEquals(expectedArgs, currentArgs, expectation.expectsExactArgCount);
});

var expectationsToApply = expectationsWithMatchingArgs.filter(function (expectation) {
var expectationsToApply = filter.call(expectationsWithMatchingArgs, function (expectation) {
return !expectation.met() && expectation.allowsCall(thisValue, args);
});

Expand Down

0 comments on commit 56ca580

Please sign in to comment.