Skip to content

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
@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