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

Use identity instead of creating a new function #879

Merged
merged 1 commit into from
Dec 1, 2012

Conversation

spadgos
Copy link
Contributor

@spadgos spadgos commented Dec 1, 2012

The compact function uses a function which casts each member to a Boolean, however this isn't needed since filter just checks for truthiness, not === true.

This change reuses the _.identity function, which has the same effect and doesn't require creating a new function on each call.

jdalton added a commit that referenced this pull request Dec 1, 2012
Use identity instead of creating a new function in `_.compact`.
@jdalton jdalton merged commit 0ca412d into jashkenas:master Dec 1, 2012
@spadgos
Copy link
Contributor Author

spadgos commented Dec 2, 2012

@jdalton I benchmarked Boolean vs function (x) { return x } vs function (x) { return !!x; }, and Boolean ended up considerably slower actually. http://jsperf.com/filter-identity-vs-boolean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants