Skip to content

Make union() deduplicate regardless of array size#2809

Open
Noethix55555 wants to merge 1 commit into
Vincit:mainfrom
Noethix55555:fix/union-dedupe-consistency
Open

Make union() deduplicate regardless of array size#2809
Noethix55555 wants to merge 1 commit into
Vincit:mainfrom
Noethix55555:fix/union-dedupe-consistency

Conversation

@Noethix55555

Copy link
Copy Markdown

union() in lib/utils/objectUtils.js switches implementation based on input size: a Set for large arrays (which dedupes both inputs) and a plain copy of the first array for small ones (which only dedupes the second). So duplicates in the first array survive only on the small-array path:

union([1, 1, 2], [2, 3])   // returns [1, 1, 2, 3], expected [1, 2, 3]

The function is used when merging RelationExpression nodes ($modify, $childNames), where the result is expected to be a set.

Fix dedupes the first array on the small path too, matching unionGeneric. Added a case to the union unit tests in tests/unit/utils.js; it fails on the current code and passes with the change. The full tests/unit/utils.js suite passes.

union() used a Set for large inputs but a plain copy of the first array for small ones, so duplicates in the first array survived only on the small-array path. union([1, 1, 2], [2, 3]) returned [1, 1, 2, 3] instead of [1, 2, 3]. Dedupe the first array on the small path too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants