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
26
const errors = require ( 'internal/errors' ) ;
28
27
@@ -115,10 +114,9 @@ function areSimilarRegExps(a, b) {
115
114
}
116
115
117
116
// For small buffers it's faster to compare the buffer in a loop. The c++
118
- // barrier including the Buffer.from operation takes the advantage of the faster
119
- // compare otherwise. 300 was the number after which compare became faster .
117
+ // barrier including the Uint8Array operation takes the advantage of the faster
118
+ // binary compare otherwise. The break even point was at about 300 characters .
120
119
function areSimilarTypedArrays ( a , b ) {
121
- const { from } = require ( 'buffer' ) . Buffer ;
122
120
const len = a . byteLength ;
123
121
if ( len !== b . byteLength ) {
124
122
return false ;
@@ -131,8 +129,8 @@ function areSimilarTypedArrays(a, b) {
131
129
}
132
130
return true ;
133
131
}
134
- return compare ( from ( a . buffer , a . byteOffset , len ) ,
135
- from ( b . buffer , b . byteOffset , b . byteLength ) ) === 0 ;
132
+ return compare ( new Uint8Array ( a . buffer , a . byteOffset , len ) ,
133
+ new Uint8Array ( b . buffer , b . byteOffset , b . byteLength ) ) === 0 ;
136
134
}
137
135
138
136
function isFloatTypedArrayTag ( tag ) {
@@ -186,11 +184,11 @@ function strictDeepEqual(actual, expected) {
186
184
// Skip testing the part below and continue in the callee function.
187
185
return ;
188
186
}
189
- if ( util . isDate ( actual ) ) {
187
+ if ( isDate ( actual ) ) {
190
188
if ( actual . getTime ( ) !== expected . getTime ( ) ) {
191
189
return false ;
192
190
}
193
- } else if ( util . isRegExp ( actual ) ) {
191
+ } else if ( isRegExp ( actual ) ) {
194
192
if ( ! areSimilarRegExps ( actual , expected ) ) {
195
193
return false ;
196
194
}
@@ -219,10 +217,10 @@ function looseDeepEqual(actual, expected) {
219
217
if ( expected === null || typeof expected !== 'object' ) {
220
218
return false ;
221
219
}
222
- if ( util . isDate ( actual ) && util . isDate ( expected ) ) {
220
+ if ( isDate ( actual ) && isDate ( expected ) ) {
223
221
return actual . getTime ( ) === expected . getTime ( ) ;
224
222
}
225
- if ( util . isRegExp ( actual ) && util . isRegExp ( expected ) ) {
223
+ if ( isRegExp ( actual ) && isRegExp ( expected ) ) {
226
224
return areSimilarRegExps ( actual , expected ) ;
227
225
}
228
226
const actualTag = objectToString ( actual ) ;
0 commit comments