Skip to content

Commit

Permalink
Merge de96ce1 into d9741b3
Browse files Browse the repository at this point in the history
  • Loading branch information
sktguha committed Sep 25, 2020
2 parents d9741b3 + de96ce1 commit 54f91f2
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 77 deletions.
16 changes: 15 additions & 1 deletion modules/isEqual.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import _ from './underscore.js';
import { toString, SymbolProto } from './_setup.js';
import { toString, SymbolProto, root } from './_setup.js';
import getByteLength from './_getByteLength.js';
import isTypedArray from './isTypedArray.js';
import isFunction from './isFunction.js';
import keys from './keys.js';
import has from './_has.js';
import toDataView from './_toDataView.js';
import bind from './bind.js';

// Internal recursive comparison function for `_.isEqual`.
function eq(a, b, aStack, bStack) {
Expand All @@ -22,6 +23,9 @@ function eq(a, b, aStack, bStack) {
return deepEq(a, b, aStack, bStack);
}

// Get Buffer.from function, if present(usually in node.js environment)
var bufferFrom = root.Buffer && root.Buffer.from && bind(root.Buffer.from, root.Buffer);

// Internal recursive comparison function for `_.isEqual`.
function deepEq(a, b, aStack, bStack) {
// Unwrap any wrapped objects.
Expand Down Expand Up @@ -53,6 +57,11 @@ function deepEq(a, b, aStack, bStack) {
case '[object Symbol]':
return SymbolProto.valueOf.call(a) === SymbolProto.valueOf.call(b);
case '[object ArrayBuffer]':
// If Buffer.from function is present(usually in nodejs environments), use that as
// that will be faster
if (bufferFrom) {
return bufferFrom(a).equals(bufferFrom(b));
}
// Coerce to `DataView` so we can fall through to the next case.
return deepEq(toDataView(a), toDataView(b), aStack, bStack);
case '[object DataView]':
Expand All @@ -68,6 +77,11 @@ function deepEq(a, b, aStack, bStack) {
}

if (isTypedArray(a)) {
// If Buffer.from function is present(usually in nodejs environments), use that as
// that will be faster
if (bufferFrom) {
return bufferFrom(a).equals(bufferFrom(b));
}
// Coerce typed arrays to `DataView`.
return deepEq(toDataView(a), toDataView(b), aStack, bStack);
}
Expand Down
87 changes: 50 additions & 37 deletions underscore-esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion underscore-esm.js.map

Large diffs are not rendered by default.

87 changes: 50 additions & 37 deletions underscore.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion underscore.js.map

Large diffs are not rendered by default.

0 comments on commit 54f91f2

Please sign in to comment.