assert: simplify logic of testing buffer equality
authorAlex Yursha <alexyursha@gmail.com>
Tue, 17 Mar 2015 14:12:51 +0000 (17:12 +0300)
committerBrendan Ashworth <brendan.ashworth@me.com>
Tue, 24 Mar 2015 02:10:04 +0000 (19:10 -0700)
Delegate buffer equality check to `buffer.equals()`

PR-URL: https://github.com/iojs/io.js/pull/1171
Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
Reviewed-By: Christian Vaagland Tellnes <christian@tellnes.com>
lib/assert.js

index 7524a62f9372a0f7698a28e03df7ed68be78f4fe..4a01e5c7f0b3560c078725e6f86d41e75057e58a 100644 (file)
@@ -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.