Skip to content

Commit 6d11a55

Browse files
committed
Added create with initial capacity, minor fix
1 parent 9561bfc commit 6d11a55

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

rxjava-core/src/main/java/rx/subjects/SubjectSubscriptionManager.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
import java.util.Arrays;
1919
import java.util.Collection;
20-
import java.util.Collections;
21-
import java.util.List;
2220
import java.util.concurrent.CountDownLatch;
2321
import java.util.concurrent.atomic.AtomicReference;
2422

@@ -126,7 +124,7 @@ protected void terminate(Action1<Collection<SubjectObserver<? super T>>> onTermi
126124
*/
127125
try {
128126
// had to circumvent type check, we know what the array contains
129-
onTerminate.call((Collection)newState.observersList);
127+
onTerminate.call((Collection)Arrays.asList(newState.observers));
130128
} finally {
131129
// mark that termination is completed
132130
newState.terminationLatch.countDown();
@@ -141,33 +139,29 @@ public SubjectObserver<Object>[] rawSnapshot() {
141139
return state.get().observers;
142140
}
143141

142+
@SuppressWarnings("rawtypes")
144143
protected static class State<T> {
145144
final boolean terminated;
146145
final CountDownLatch terminationLatch;
147146
final Subscription[] subscriptions;
148-
final SubjectObserver<Object>[] observers;
147+
final SubjectObserver[] observers;
149148
// to avoid lots of empty arrays
150149
final Subscription[] EMPTY_S = new Subscription[0];
151-
@SuppressWarnings("rawtypes")
152150
// to avoid lots of empty arrays
153151
final SubjectObserver[] EMPTY_O = new SubjectObserver[0];
154-
@SuppressWarnings("rawtypes")
155-
final List<SubjectObserver<Object>> observersList;
156152
private State(boolean isTerminated, CountDownLatch terminationLatch,
157153
Subscription[] subscriptions, SubjectObserver[] observers) {
158154
this.terminationLatch = terminationLatch;
159155
this.terminated = isTerminated;
160156
this.subscriptions = subscriptions;
161157
this.observers = observers;
162-
this.observersList = Arrays.asList(this.observers);
163158
}
164159

165160
State() {
166161
this.terminated = false;
167162
this.terminationLatch = null;
168163
this.subscriptions = EMPTY_S;
169164
this.observers = EMPTY_O;
170-
observersList = Collections.emptyList();
171165
}
172166

173167
public State<T> terminate() {

0 commit comments

Comments
 (0)