Skip to content
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

cache map.get() for size wins #100

Merged
merged 2 commits into from
May 27, 2020
Merged

cache map.get() for size wins #100

merged 2 commits into from
May 27, 2020

Conversation

developit
Copy link
Owner

@developit developit commented May 26, 2020

This is a follow-up to #99 that reduces size a bit by caching the result of handlers.get() and reusing that value for both the existence check (are any handlers registered) and the index calculation.

@github-actions
Copy link

github-actions bot commented May 26, 2020

Size Change: -18 B (1%)

Total Size: 930 B

Filename Size Change
dist/mitt.es.js 213 B -6 B (2%)
dist/mitt.js 213 B -2 B (0%)
dist/mitt.modern.js 212 B -6 B (2%)
dist/mitt.umd.js 292 B -4 B (1%)

compressed-size-action

all.get(type).splice(all.get(type).indexOf(handler) >>> 0, 1);
const handlers = all.get(type);
if (handlers) {
handlers.splice(handlers.indexOf(handler) >>> 0, 1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to use Set for the handlers instead?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For speed yes, but Set rejects duplicates. EventEmitter, the API contract mitt adheres to, allows duplicate handlers.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean I can register the same functions twice? That is really interesting.

@developit developit merged commit 3bce9a1 into master May 27, 2020
@developit developit deleted the map-cache-size branch May 27, 2020 16:33
@developit
Copy link
Owner Author

Released in 2.0.1.

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