fast-equals 5.1.2 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +31 -26
- package/dist/cjs/index.cjs +42 -36
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +42 -36
- package/dist/esm/index.mjs.map +1 -1
- package/dist/min/index.js +1 -1
- package/dist/umd/index.js +42 -36
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -2
- package/src/equals.ts +58 -49
package/package.json
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"decircularize": "^1.0.0",
|
|
23
23
|
"deep-eql": "^4.1.4",
|
|
24
24
|
"deep-equal": "^2.0.5",
|
|
25
|
+
"dequal": "^2.0.3",
|
|
25
26
|
"eslint": "^8.57.1",
|
|
26
27
|
"eslint-friendly-formatter": "^4.0.1",
|
|
27
28
|
"eslint-webpack-plugin": "^4.0.0",
|
|
@@ -98,7 +99,7 @@
|
|
|
98
99
|
"start": "npm run dev",
|
|
99
100
|
"release": "release-it",
|
|
100
101
|
"release:beta": "release-it --config=.release-it.beta.json",
|
|
101
|
-
"release:scripts": "npm run typecheck && npm run lint && npm run test:coverage && npm run
|
|
102
|
+
"release:scripts": "npm run typecheck && npm run lint && npm run test:coverage && npm run build",
|
|
102
103
|
"test": "NODE_PATH=. jest",
|
|
103
104
|
"test:coverage": "rm -rf coverage && npm test -- --coverage",
|
|
104
105
|
"test:watch": "npm test -- --watch",
|
|
@@ -107,5 +108,5 @@
|
|
|
107
108
|
"sideEffects": false,
|
|
108
109
|
"type": "module",
|
|
109
110
|
"types": "./index.d.ts",
|
|
110
|
-
"version": "5.
|
|
111
|
+
"version": "5.2.0"
|
|
111
112
|
}
|
package/src/equals.ts
CHANGED
|
@@ -6,7 +6,9 @@ import type {
|
|
|
6
6
|
TypedArray,
|
|
7
7
|
} from './internalTypes';
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const PREACT_VNODE = '__v';
|
|
10
|
+
const PREACT_OWNER = '__o';
|
|
11
|
+
const REACT_OWNER = '_owner';
|
|
10
12
|
|
|
11
13
|
const { getOwnPropertyDescriptor, keys } = Object;
|
|
12
14
|
|
|
@@ -66,16 +68,22 @@ export function areMapsEqual(
|
|
|
66
68
|
b: Map<any, any>,
|
|
67
69
|
state: State<any>,
|
|
68
70
|
): boolean {
|
|
69
|
-
|
|
71
|
+
const size = a.size;
|
|
72
|
+
|
|
73
|
+
if (size !== b.size) {
|
|
70
74
|
return false;
|
|
71
75
|
}
|
|
72
76
|
|
|
73
|
-
|
|
77
|
+
if (!size) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const matchedIndices: Array<true | undefined> = new Array(size);
|
|
74
82
|
const aIterable = a.entries();
|
|
75
83
|
|
|
76
|
-
let index = 0;
|
|
77
84
|
let aResult: IteratorResult<[any, any]>;
|
|
78
85
|
let bResult: IteratorResult<[any, any]>;
|
|
86
|
+
let index = 0;
|
|
79
87
|
|
|
80
88
|
while ((aResult = aIterable.next())) {
|
|
81
89
|
if (aResult.done) {
|
|
@@ -92,17 +100,20 @@ export function areMapsEqual(
|
|
|
92
100
|
break;
|
|
93
101
|
}
|
|
94
102
|
|
|
95
|
-
|
|
96
|
-
|
|
103
|
+
if (matchedIndices[matchIndex]) {
|
|
104
|
+
matchIndex++;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const aEntry = aResult.value;
|
|
109
|
+
const bEntry = bResult.value;
|
|
97
110
|
|
|
98
111
|
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
(hasMatch =
|
|
102
|
-
state.equals(aKey, bKey, index, matchIndex, a, b, state) &&
|
|
103
|
-
state.equals(aValue, bValue, aKey, bKey, a, b, state))
|
|
112
|
+
state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state) &&
|
|
113
|
+
state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)
|
|
104
114
|
) {
|
|
105
|
-
matchedIndices[matchIndex] = true;
|
|
115
|
+
hasMatch = matchedIndices[matchIndex] = true;
|
|
116
|
+
break;
|
|
106
117
|
}
|
|
107
118
|
|
|
108
119
|
matchIndex++;
|
|
@@ -139,27 +150,12 @@ export function areObjectsEqual(
|
|
|
139
150
|
return false;
|
|
140
151
|
}
|
|
141
152
|
|
|
142
|
-
let property: string;
|
|
143
|
-
|
|
144
153
|
// Decrementing `while` showed faster results than either incrementing or
|
|
145
154
|
// decrementing `for` loop and than an incrementing `while` loop. Declarative
|
|
146
155
|
// methods like `some` / `every` were not used to avoid incurring the garbage
|
|
147
156
|
// cost of anonymous callbacks.
|
|
148
157
|
while (index-- > 0) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
property === OWNER &&
|
|
153
|
-
(a.$$typeof || b.$$typeof) &&
|
|
154
|
-
a.$$typeof !== b.$$typeof
|
|
155
|
-
) {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (
|
|
160
|
-
!hasOwn(b, property) ||
|
|
161
|
-
!state.equals(a[property], b[property], property, property, a, b, state)
|
|
162
|
-
) {
|
|
158
|
+
if (!isPropertyEqual(a, b, state, properties[index]!)) {
|
|
163
159
|
return false;
|
|
164
160
|
}
|
|
165
161
|
}
|
|
@@ -194,21 +190,7 @@ export function areObjectsEqualStrict(
|
|
|
194
190
|
while (index-- > 0) {
|
|
195
191
|
property = properties[index]!;
|
|
196
192
|
|
|
197
|
-
if (
|
|
198
|
-
property === OWNER &&
|
|
199
|
-
(a.$$typeof || b.$$typeof) &&
|
|
200
|
-
a.$$typeof !== b.$$typeof
|
|
201
|
-
) {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (!hasOwn(b, property)) {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (
|
|
210
|
-
!state.equals(a[property], b[property], property, property, a, b, state)
|
|
211
|
-
) {
|
|
193
|
+
if (!isPropertyEqual(a, b, state, property)) {
|
|
212
194
|
return false;
|
|
213
195
|
}
|
|
214
196
|
|
|
@@ -255,11 +237,17 @@ export function areSetsEqual(
|
|
|
255
237
|
b: Set<any>,
|
|
256
238
|
state: State<any>,
|
|
257
239
|
): boolean {
|
|
258
|
-
|
|
240
|
+
const size = a.size;
|
|
241
|
+
|
|
242
|
+
if (size !== b.size) {
|
|
259
243
|
return false;
|
|
260
244
|
}
|
|
261
245
|
|
|
262
|
-
|
|
246
|
+
if (!size) {
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const matchedIndices: Array<true | undefined> = new Array(size);
|
|
263
251
|
const aIterable = a.values();
|
|
264
252
|
|
|
265
253
|
let aResult: IteratorResult<any>;
|
|
@@ -281,9 +269,8 @@ export function areSetsEqual(
|
|
|
281
269
|
}
|
|
282
270
|
|
|
283
271
|
if (
|
|
284
|
-
!hasMatch &&
|
|
285
272
|
!matchedIndices[matchIndex] &&
|
|
286
|
-
|
|
273
|
+
state.equals(
|
|
287
274
|
aResult.value,
|
|
288
275
|
bResult.value,
|
|
289
276
|
aResult.value,
|
|
@@ -291,9 +278,10 @@ export function areSetsEqual(
|
|
|
291
278
|
a,
|
|
292
279
|
b,
|
|
293
280
|
state,
|
|
294
|
-
)
|
|
281
|
+
)
|
|
295
282
|
) {
|
|
296
|
-
matchedIndices[matchIndex] = true;
|
|
283
|
+
hasMatch = matchedIndices[matchIndex] = true;
|
|
284
|
+
break;
|
|
297
285
|
}
|
|
298
286
|
|
|
299
287
|
matchIndex++;
|
|
@@ -340,3 +328,24 @@ export function areUrlsEqual(a: URL, b: URL): boolean {
|
|
|
340
328
|
a.password === b.password
|
|
341
329
|
);
|
|
342
330
|
}
|
|
331
|
+
|
|
332
|
+
function isPropertyEqual(
|
|
333
|
+
a: Dictionary,
|
|
334
|
+
b: Dictionary,
|
|
335
|
+
state: State<any>,
|
|
336
|
+
property: string | symbol,
|
|
337
|
+
) {
|
|
338
|
+
if (
|
|
339
|
+
(property === REACT_OWNER ||
|
|
340
|
+
property === PREACT_OWNER ||
|
|
341
|
+
property === PREACT_VNODE) &&
|
|
342
|
+
(a.$$typeof || b.$$typeof)
|
|
343
|
+
) {
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return (
|
|
348
|
+
hasOwn(b, property) &&
|
|
349
|
+
state.equals(a[property], b[property], property, property, a, b, state)
|
|
350
|
+
);
|
|
351
|
+
}
|