2121'use strict' ;
2222
2323const { compare } = process . binding ( 'buffer' ) ;
24- const util = require ( 'util' ) ;
25- const { isSet, isMap } = process . binding ( 'util' ) ;
24+ const { isSet, isMap, isDate, isRegExp } = process . binding ( 'util' ) ;
2625const { objectToString } = require ( 'internal/util' ) ;
27- const { Buffer } = require ( 'buffer' ) ;
2826const errors = require ( 'internal/errors' ) ;
2927
3028// The assert module provides functions that throw
@@ -108,8 +106,8 @@ function areSimilarRegExps(a, b) {
108106}
109107
110108// For small buffers it's faster to compare the buffer in a loop. The c++
111- // barrier including the Buffer.from operation takes the advantage of the faster
112- // compare otherwise. 300 was the number after which compare became faster .
109+ // barrier including the Uint8Array operation takes the advantage of the faster
110+ // binary compare otherwise. The break even point was at about 300 characters .
113111function areSimilarTypedArrays ( a , b ) {
114112 const len = a . byteLength ;
115113 if ( len !== b . byteLength ) {
@@ -123,12 +121,8 @@ function areSimilarTypedArrays(a, b) {
123121 }
124122 return true ;
125123 }
126- return compare ( Buffer . from ( a . buffer ,
127- a . byteOffset ,
128- len ) ,
129- Buffer . from ( b . buffer ,
130- b . byteOffset ,
131- b . byteLength ) ) === 0 ;
124+ return compare ( new Uint8Array ( a . buffer , a . byteOffset , len ) ,
125+ new Uint8Array ( b . buffer , b . byteOffset , b . byteLength ) ) === 0 ;
132126}
133127
134128function isFloatTypedArrayTag ( tag ) {
@@ -189,11 +183,11 @@ function strictDeepEqual(actual, expected) {
189183 // Skip testing the part below and continue in the callee function.
190184 return ;
191185 }
192- if ( util . isDate ( actual ) ) {
186+ if ( isDate ( actual ) ) {
193187 if ( actual . getTime ( ) !== expected . getTime ( ) ) {
194188 return false ;
195189 }
196- } else if ( util . isRegExp ( actual ) ) {
190+ } else if ( isRegExp ( actual ) ) {
197191 if ( ! areSimilarRegExps ( actual , expected ) ) {
198192 return false ;
199193 }
@@ -229,10 +223,10 @@ function looseDeepEqual(actual, expected) {
229223 if ( expected === null || typeof expected !== 'object' ) {
230224 return false ;
231225 }
232- if ( util . isDate ( actual ) && util . isDate ( expected ) ) {
226+ if ( isDate ( actual ) && isDate ( expected ) ) {
233227 return actual . getTime ( ) === expected . getTime ( ) ;
234228 }
235- if ( util . isRegExp ( actual ) && util . isRegExp ( expected ) ) {
229+ if ( isRegExp ( actual ) && isRegExp ( expected ) ) {
236230 return areSimilarRegExps ( actual , expected ) ;
237231 }
238232 if ( actual instanceof Error && expected instanceof Error ) {
0 commit comments