thomaslevesque / WeakEvent

Generic weak event implementation
Apache License 2.0
182 stars 23 forks source link

Reduce cost of events with no subscribers #31

Closed thomaslevesque closed 5 years ago

thomaslevesque commented 5 years ago

Split from #30, in which @mhn65536 suggested that the cost of unused events (i.e. with no subscribers) could be reduced.

Although the approach suggested by @mhn65536 cannot be used due to thread-safety reasons, there's a way to make things better by lazily allocating the handlers collection. The WeakEventSource instance will still be allocated.

thomaslevesque commented 5 years ago

Implemented in https://github.com/thomaslevesque/WeakEvent/commit/0f374ef0badebd83fe46421b05082a8c97c6afa4