21
21
'use strict' ;
22
22
23
23
const { 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' ) ;
26
25
const { objectToString } = require ( 'internal/util' ) ;
27
- const { Buffer } = require ( 'buffer' ) ;
28
26
const errors = require ( 'internal/errors' ) ;
29
27
30
28
// The assert module provides functions that throw
@@ -108,8 +106,8 @@ function areSimilarRegExps(a, b) {
108
106
}
109
107
110
108
// 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 .
113
111
function areSimilarTypedArrays ( a , b ) {
114
112
const len = a . byteLength ;
115
113
if ( len !== b . byteLength ) {
@@ -123,12 +121,8 @@ function areSimilarTypedArrays(a, b) {
123
121
}
124
122
return true ;
125
123
}
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 ;
132
126
}
133
127
134
128
function isFloatTypedArrayTag ( tag ) {
@@ -189,11 +183,11 @@ function strictDeepEqual(actual, expected) {
189
183
// Skip testing the part below and continue in the callee function.
190
184
return ;
191
185
}
192
- if ( util . isDate ( actual ) ) {
186
+ if ( isDate ( actual ) ) {
193
187
if ( actual . getTime ( ) !== expected . getTime ( ) ) {
194
188
return false ;
195
189
}
196
- } else if ( util . isRegExp ( actual ) ) {
190
+ } else if ( isRegExp ( actual ) ) {
197
191
if ( ! areSimilarRegExps ( actual , expected ) ) {
198
192
return false ;
199
193
}
@@ -229,10 +223,10 @@ function looseDeepEqual(actual, expected) {
229
223
if ( expected === null || typeof expected !== 'object' ) {
230
224
return false ;
231
225
}
232
- if ( util . isDate ( actual ) && util . isDate ( expected ) ) {
226
+ if ( isDate ( actual ) && isDate ( expected ) ) {
233
227
return actual . getTime ( ) === expected . getTime ( ) ;
234
228
}
235
- if ( util . isRegExp ( actual ) && util . isRegExp ( expected ) ) {
229
+ if ( isRegExp ( actual ) && isRegExp ( expected ) ) {
236
230
return areSimilarRegExps ( actual , expected ) ;
237
231
}
238
232
if ( actual instanceof Error && expected instanceof Error ) {
0 commit comments