Skip to content

Fix issue with OrderedMap, OrderedSet and hashCode #2005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

jdeniau
Copy link
Member

@jdeniau jdeniau commented Jul 22, 2024

when generating the hashCode of an element, we do use the size returned by __iterate. But in case of Ordered element, the internal representation of the underlying list might contain undefined elements :

Example:

const m = OrderedMap({a:'a', b:'b'}).remove('a')

m.size is 1, the __iterate function will iterate only one time on the b key, but the internal _list element, will have two elements: [undefined, ['b', 'b']]:

image
See https://runkit.com/jdeniau/immutable-hashcode-using-internal-list-size

I think that we should not use the value returned by __iterate, and use the object size directly.

Fixes #2002

@jdeniau jdeniau force-pushed the hash-code-size-issue-with-ordered branch from befe268 to 0dc830c Compare July 22, 2024 09:27
@jdeniau jdeniau merged commit ce2b028 into 5.x Jul 22, 2024
5 checks passed
@jdeniau jdeniau deleted the hash-code-size-issue-with-ordered branch July 22, 2024 13:08
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.

1 participant