Skip to content

Commit

Permalink
perf: faster equals with Object.is short circuit (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
agriffis authored Feb 21, 2024
1 parent 79013c7 commit 4e35a46
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 133 deletions.
1 change: 1 addition & 0 deletions dist/rambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ function parseRegex(maybeRegex) {
}
function equals(a, b) {
if (arguments.length === 1) return _b => equals(a, _b);
if (Object.is(a, b)) return true;
const aType = type(a);
if (aType !== type(b)) return false;
if (aType === 'Function') return a.name === undefined ? false : a.name === b.name;
Expand Down
2 changes: 1 addition & 1 deletion dist/rambda.umd.js

Large diffs are not rendered by default.

131 changes: 0 additions & 131 deletions source/__snapshots__/equals.spec.js.snap

This file was deleted.

2 changes: 2 additions & 0 deletions source/equals.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function parseRegex(maybeRegex){
export function equals(a, b){
if (arguments.length === 1) return _b => equals(a, _b)

if (Object.is(a, b)) return true

const aType = type(a)

if (aType !== type(b)) return false
Expand Down
2 changes: 1 addition & 1 deletion source/equals.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ describe('brute force', () => {
{
"ERRORS_MESSAGE_MISMATCH": 0,
"ERRORS_TYPE_MISMATCH": 0,
"RESULTS_MISMATCH": 8,
"RESULTS_MISMATCH": 0,
"SHOULD_NOT_THROW": 0,
"SHOULD_THROW": 0,
"TOTAL_TESTS": 289,
Expand Down
2 changes: 2 additions & 0 deletions src/equals.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function parseRegex(maybeRegex){
export function equals(a, b){
if (arguments.length === 1) return _b => equals(a, _b)

if (Object.is(a, b)) return true

const aType = type(a)

if (aType !== type(b)) return false
Expand Down

0 comments on commit 4e35a46

Please sign in to comment.