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

Optimize AbstractListenableFuture Memory Allocations #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,22 @@ protected void notifyListeners() {
* @param future the future to pass on to the listeners.
*/
protected void notifyListeners(final Future<?> future) {
final List<GenericCompletionListener<? extends Future<T>>> copy =
new ArrayList<GenericCompletionListener<? extends Future<T>>>();
final List<GenericCompletionListener<? extends Future<T>>> copy;
synchronized(this) {
copy.addAll(listeners);
if (listeners.isEmpty()) {
copy = null;
}
else {
copy = new ArrayList<GenericCompletionListener
<? extends Future<T>>>(listeners);
}
listeners = new ArrayList<GenericCompletionListener<? extends Future<T>>>();
}
for (GenericCompletionListener<? extends Future<? super T>> listener
: copy) {
notifyListener(executor(), future, listener);
if (copy != null) {
for (GenericCompletionListener<? extends Future<? super T>> listener
: copy) {
notifyListener(executor(), future, listener);
}
}
}

Expand Down