Skip to content

Commit 7dd5e82

Browse files
yurshabrendanashworth
authored andcommitted
assert: simplify logic of testing buffer equality
Delegate buffer equality check to `buffer.equals()` PR-URL: #1171 Reviewed-By: Brendan Ashworth <[email protected]> Reviewed-By: Christian Vaagland Tellnes <[email protected]>
1 parent 269e46b commit 7dd5e82

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

lib/assert.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'use strict';
2626

2727
// UTILITY
28+
const compare = process.binding('buffer').compare;
2829
const util = require('util');
2930
const pSlice = Array.prototype.slice;
3031

@@ -145,13 +146,7 @@ function _deepEqual(actual, expected, strict) {
145146
if (actual === expected) {
146147
return true;
147148
} else if (actual instanceof Buffer && expected instanceof Buffer) {
148-
if (actual.length != expected.length) return false;
149-
150-
for (var i = 0; i < actual.length; i++) {
151-
if (actual[i] !== expected[i]) return false;
152-
}
153-
154-
return true;
149+
return compare(actual, expected) === 0;
155150

156151
// 7.2. If the expected value is a Date object, the actual value is
157152
// equivalent if it is also a Date object that refers to the same time.

0 commit comments

Comments
 (0)