Skip to content

Use Object.create(null) instead of {} to compute keyed diffs #180

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jfmengels
Copy link

This is a minor improvement pull request.

{} creates an empty object but which still contains methods and properties like toString. Checking changes[key] when the key is for instance toString creates false positives in that check.

I was looking whether into whether this caused bugs, but in practice, the algorithms in _VirtualDom_insertNode and _VirtualDom_removeNode end up with the correct behavior because they recurse with a modified key, but do so with an unnecessary iteration.

Object.create(null) creates an empty object without any methods or properties, leading to no false positives and one less unnecessary iteration.

`{}` creates an empty object but which still contains methods and
properties like `toString`. Checking `changes[key]` when the key is
for instance `toString` creates false positives in that check.

In practice, the algorithms in `_VirtualDom_insertNode` and `_VirtualDom_removeNode`
end up with the correct behavior because they recurse with a modified
key, but do so with an unnecessary iteration.

`Object.create(null)` create an empty object without any methods or
properties, leading to no false positives.
@mozfreddyb
Copy link

Why not Map()?

@jfmengels
Copy link
Author

Because Elm currently compiles down to ES5, where Map is not available.

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