GeezerVison is showing github.com — assert: optimize partial comparison of two `Set`s · nodejs/node@a4fa31a
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/assert.js +5-13Lines changed: 5 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -414,33 +414,25 @@ function compareBranch( |
414 | 414 | } |
415 | 415 |
|
416 | 416 | // Check for Set object equality |
417 | | - // TODO(aduh95): switch to `SetPrototypeIsSubsetOf` when it's available |
418 | 417 | if (isSet(actual) && isSet(expected)) { |
419 | 418 | if (expected.size > actual.size) { |
420 | 419 | return false; // `expected` can't be a subset if it has more elements |
421 | 420 | } |
422 | 421 |
|
423 | 422 | if (isDeepEqual === undefined) lazyLoadComparison(); |
424 | 423 |
|
425 | | - const actualArray = ArrayFrom(actual); |
426 | | - const expectedArray = ArrayFrom(expected); |
| 424 | + const actualArray = ArrayFrom(FunctionPrototypeCall(SafeSet.prototype[SymbolIterator], actual)); |
| 425 | + const expectedIterator = FunctionPrototypeCall(SafeSet.prototype[SymbolIterator], expected); |
427 | 426 | const usedIndices = new SafeSet(); |
428 | 427 |
|
429 | | - for (let expectedIdx = 0; expectedIdx < expectedArray.length; expectedIdx++) { |
430 | | - const expectedItem = expectedArray[expectedIdx]; |
431 | | - let found = false; |
432 | | - |
| 428 | + expectedIteration: for (const expectedItem of expectedIterator) { |
433 | 429 | for (let actualIdx = 0; actualIdx < actualArray.length; actualIdx++) { |
434 | 430 | if (!usedIndices.has(actualIdx) && isDeepStrictEqual(actualArray[actualIdx], expectedItem)) { |
435 | 431 | usedIndices.add(actualIdx); |
436 | | - found = true; |
437 | | - break; |
| 432 | + continue expectedIteration; |
438 | 433 | } |
439 | 434 | } |
440 | | - |
441 | | - if (!found) { |
442 | | - return false; |
443 | | - } |
| 435 | + return false; |
444 | 436 | } |
445 | 437 |
|
446 | 438 | return true; |
|