From 7dd5e824be53e222af63cc86e89b7ab7f841901c Mon Sep 17 00:00:00 2001 From: Alex Yursha Date: Tue, 17 Mar 2015 17:12:51 +0300 Subject: [PATCH] assert: simplify logic of testing buffer equality Delegate buffer equality check to `buffer.equals()` PR-URL: https://github.com/iojs/io.js/pull/1171 Reviewed-By: Brendan Ashworth Reviewed-By: Christian Vaagland Tellnes --- lib/assert.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index 7524a62f93..4a01e5c7f0 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -25,6 +25,7 @@ 'use strict'; // UTILITY +const compare = process.binding('buffer').compare; const util = require('util'); const pSlice = Array.prototype.slice; @@ -145,13 +146,7 @@ function _deepEqual(actual, expected, strict) { if (actual === expected) { return true; } else if (actual instanceof Buffer && expected instanceof Buffer) { - if (actual.length != expected.length) return false; - - for (var i = 0; i < actual.length; i++) { - if (actual[i] !== expected[i]) return false; - } - - return true; + return compare(actual, expected) === 0; // 7.2. If the expected value is a Date object, the actual value is // equivalent if it is also a Date object that refers to the same time.