events: optimize adding and removing of listeners
authorBrian White <mscdex@mscdex.net>
Wed, 11 Feb 2015 22:00:12 +0000 (17:00 -0500)
committerBen Noordhuis <info@bnoordhuis.nl>
Wed, 11 Feb 2015 22:06:26 +0000 (23:06 +0100)
commit7061669dba26337e47e258385dd58e400881dff1
treef6e4032f2c52c3ee2b30c32f22e6f07b5b9650a8
parent630f63633490f60a292e62bb7a82bd9ea4de68c4
events: optimize adding and removing of listeners

These optimizations result in >2x speedup in the ee-add-remove
benchmark:

* Don't mutate array.length when removing the last listener for
an event
* Don't bother checking max listeners if listeners isn't an array
* Don't call delete when removing the last event in _events, just
re-assign a new object instead

PR-URL: https://github.com/iojs/io.js/pull/785
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Evan Lucas <evanlucas@me.com>
lib/events.js