Don't construct unnecessarily asymmetricEqualityTesterArgCompatShims
This speeds up MatchersUtil#equals by about 6-7x.
This commit is contained in:
@@ -279,7 +279,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
j$.isAsymmetricEqualityTester_ = function(obj) {
|
j$.isAsymmetricEqualityTester_ = function(obj) {
|
||||||
return obj && j$.isA_('Function', obj.asymmetricMatch);
|
return obj ? j$.isA_('Function', obj.asymmetricMatch) : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.getType_ = function(value) {
|
j$.getType_ = function(value) {
|
||||||
@@ -4494,13 +4494,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
MatchersUtil.prototype.asymmetricMatch_ = function(a, b, aStack, bStack, customTesters, diffBuilder) {
|
MatchersUtil.prototype.asymmetricMatch_ = function(a, b, aStack, bStack, customTesters, diffBuilder) {
|
||||||
var asymmetricA = j$.isAsymmetricEqualityTester_(a),
|
var asymmetricA = j$.isAsymmetricEqualityTester_(a),
|
||||||
asymmetricB = j$.isAsymmetricEqualityTester_(b),
|
asymmetricB = j$.isAsymmetricEqualityTester_(b),
|
||||||
shim = j$.asymmetricEqualityTesterArgCompatShim(this, customTesters),
|
shim,
|
||||||
result;
|
result;
|
||||||
|
|
||||||
if (asymmetricA && asymmetricB) {
|
if (asymmetricA === asymmetricB) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shim = j$.asymmetricEqualityTesterArgCompatShim(this, customTesters);
|
||||||
|
|
||||||
if (asymmetricA) {
|
if (asymmetricA) {
|
||||||
result = a.asymmetricMatch(b, shim);
|
result = a.asymmetricMatch(b, shim);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
|||||||
@@ -30,4 +30,25 @@ describe('base helpers', function() {
|
|||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isAsymmetricEqualityTester_', function() {
|
||||||
|
it('returns false when the argument is falsy', function() {
|
||||||
|
expect(jasmineUnderTest.isAsymmetricEqualityTester_(null)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false when the argument does not have a asymmetricMatch property', function() {
|
||||||
|
var obj = {};
|
||||||
|
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns false when the argument's asymmetricMatch is not a function", function() {
|
||||||
|
var obj = { asymmetricMatch: 'yes' };
|
||||||
|
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns true when the argument's asymmetricMatch is a function", function() {
|
||||||
|
var obj = { asymmetricMatch: function() {} };
|
||||||
|
expect(jasmineUnderTest.isAsymmetricEqualityTester_(obj)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
j$.isAsymmetricEqualityTester_ = function(obj) {
|
j$.isAsymmetricEqualityTester_ = function(obj) {
|
||||||
return obj && j$.isA_('Function', obj.asymmetricMatch);
|
return obj ? j$.isA_('Function', obj.asymmetricMatch) : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
j$.getType_ = function(value) {
|
j$.getType_ = function(value) {
|
||||||
|
|||||||
@@ -90,13 +90,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
MatchersUtil.prototype.asymmetricMatch_ = function(a, b, aStack, bStack, customTesters, diffBuilder) {
|
MatchersUtil.prototype.asymmetricMatch_ = function(a, b, aStack, bStack, customTesters, diffBuilder) {
|
||||||
var asymmetricA = j$.isAsymmetricEqualityTester_(a),
|
var asymmetricA = j$.isAsymmetricEqualityTester_(a),
|
||||||
asymmetricB = j$.isAsymmetricEqualityTester_(b),
|
asymmetricB = j$.isAsymmetricEqualityTester_(b),
|
||||||
shim = j$.asymmetricEqualityTesterArgCompatShim(this, customTesters),
|
shim,
|
||||||
result;
|
result;
|
||||||
|
|
||||||
if (asymmetricA && asymmetricB) {
|
if (asymmetricA === asymmetricB) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shim = j$.asymmetricEqualityTesterArgCompatShim(this, customTesters);
|
||||||
|
|
||||||
if (asymmetricA) {
|
if (asymmetricA) {
|
||||||
result = a.asymmetricMatch(b, shim);
|
result = a.asymmetricMatch(b, shim);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
|||||||
Reference in New Issue
Block a user