Skip to content

Commit 3f8f3ea

Browse files
author
Klemen Kresnik
committed
Move for-each into synchronized block.
1 parent d733f00 commit 3f8f3ea

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/main/java/rx/subscriptions/CompositeSubscription.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,24 @@ public void add(final Subscription s) {
8585
* the collection of {@link Subscription} to add
8686
*/
8787
public void addAll(final Subscription... subscriptions) {
88-
List<Subscription> subscriptionList = new ArrayList<Subscription>(4);
89-
for (Subscription s : subscriptions) {
90-
if (!s.isUnsubscribed()) {
91-
subscriptionList.add(s);
92-
}
93-
}
94-
9588
if (!unsubscribed) {
9689
synchronized (this) {
9790
if (!unsubscribed) {
9891
if (this.subscriptions == null) {
9992
this.subscriptions = new HashSet<Subscription>(4);
10093
}
101-
this.subscriptions.addAll(subscriptionList);
94+
95+
for (Subscription s : subscriptions) {
96+
if (!s.isUnsubscribed()) {
97+
this.subscriptions.add(s);
98+
}
99+
}
102100
return;
103101
}
104102
}
105103
}
106104

107-
for (Subscription s : subscriptionList) {
105+
for (Subscription s : subscriptions) {
108106
s.unsubscribe();
109107
}
110108
}

0 commit comments

Comments
 (0)