Remove disposable allocations from routed event AddHandler in the common case. #3651
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
AddHandler
was always returningIDisposable
allowing for easy unsubscribe for the user. This PR changes this behavior to not do this by default and adds a separate function with this behavior.What is the current behavior?
Most of the
AddHandler
callers don't even use returned value (all event implementations inAvaloniaObject
just discard returnedIDisposable
). There are only a few call sites that use this feature.What is the updated/expected behavior with this PR?
Adds a separate
AddDisposableHandler
that can returnsIDisposable
that can be used to unsubscribe from the handler.Perf gains in calendar case are tiny but we can clearly see that we collect less often now as
AddHandler
is not forced to allocate all the time. But we shouldn't prevent users from not being able have non-allocatingAddHandler
to support 1% niche use case.How was the solution implemented (if it's not obvious)?
Checklist
Breaking changes
Users that are utilizing
AddHandler
return value should useAddDisposableHandler
instead.