Commit c814c7e
events: do not keep arrays with a single listener
Use the remaining listener directly if the array of listeners has only
one element after running `EventEmitter.prototype.removeListener()`.
Advantages:
- Better memory usage and better performance if no new listeners are
added for the same event.
Disadvantages:
- A new array must be created if new listeners are added for the same
event.
PR-URL: #12043
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ron Korving <ron@ronkorving.nl>1 parent 8058bae commit c814c7eCopy full SHA for c814c7e
File tree
Expand file treeCollapse file tree
2 files changed
+28
-7
lines changedOpen diff view settings
Filter options
- lib
- test/parallel
Expand file treeCollapse file tree
2 files changed
+28
-7
lines changedOpen diff view settings
Collapse file
+11-7Lines changed: 11 additions & 7 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
344 | 344 | |
345 | 345 | |
346 | 346 | |
347 | | - |
| 347 | + |
348 | 348 | |
349 | 349 | |
350 | 350 | |
| ||
356 | 356 | |
357 | 357 | |
358 | 358 | |
359 | | - |
360 | 359 | |
361 | 360 | |
362 | 361 | |
| ||
365 | 364 | |
366 | 365 | |
367 | 366 | |
| 367 | + |
| 368 | + |
368 | 369 | |
369 | 370 | |
| 371 | + |
| 372 | + |
370 | 373 | |
371 | 374 | |
372 | 375 | |
| ||
378 | 381 | |
379 | 382 | |
380 | 383 | |
381 | | - |
| 384 | + |
382 | 385 | |
383 | 386 | |
384 | 387 | |
| ||
401 | 404 | |
402 | 405 | |
403 | 406 | |
404 | | - |
| 407 | + |
| 408 | + |
405 | 409 | |
406 | 410 | |
407 | 411 | |
| ||
418 | 422 | |
419 | 423 | |
420 | 424 | |
421 | | - |
422 | | - |
423 | | - |
| 425 | + |
| 426 | + |
| 427 | + |
424 | 428 | |
425 | 429 | |
426 | 430 | |
|
Collapse file
test/parallel/test-event-emitter-remove-listeners.js
Copy file name to clipboardExpand all lines: test/parallel/test-event-emitter-remove-listeners.js+17Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
136 | 136 | |
137 | 137 | |
138 | 138 | |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
0 commit comments