Skip to content

Commit

Permalink
remove synchronization gate object. it is not needed if we simply cle…
Browse files Browse the repository at this point in the history
…ar the dictionary rather than re-assign the pointer with a newly allocated dictionary
  • Loading branch information
bvanderveen committed Aug 28, 2012
1 parent a268f31 commit d7e9b76
Showing 1 changed file with 3 additions and 4 deletions.
Expand Up @@ -395,19 +395,18 @@ + (RACSubscribable *)combineLatest:(NSArray *)subscribables reduce:(id (^)(RACTu
return [RACSubscribable createSubscribable:^(id<RACSubscriber> subscriber) {
NSMutableSet *disposables = [NSMutableSet setWithCapacity:subscribables.count];
NSMutableSet *completedSubscribables = [NSMutableSet setWithCapacity:subscribables.count];
__block NSMutableDictionary *lastValues = [NSMutableDictionary dictionaryWithCapacity:subscribables.count];
NSObject *nextGate = [NSObject new];
NSMutableDictionary *lastValues = [NSMutableDictionary dictionaryWithCapacity:subscribables.count];
for(id<RACSubscribable> subscribable in subscribables) {
RACDisposable *disposable = [subscribable subscribe:[RACSubscriber subscriberWithNext:^(id x) {
@synchronized(nextGate) {
@synchronized(lastValues) {
[lastValues setObject:x ? : [RACTupleNil tupleNil] forKey:[NSString stringWithFormat:@"%p", subscribable]];

if(lastValues.count == subscribables.count) {
NSMutableArray *orderedValues = [NSMutableArray arrayWithCapacity:subscribables.count];
for(id<RACSubscribable> o in subscribables) {
[orderedValues addObject:[lastValues objectForKey:[NSString stringWithFormat:@"%p", o]]];
}
lastValues = [NSMutableDictionary dictionaryWithCapacity:subscribables.count];
[lastValues removeAllObjects];
[subscriber sendNext:reduceBlock([RACTuple tupleWithObjectsFromArray:orderedValues])];
}
}
Expand Down

0 comments on commit d7e9b76

Please sign in to comment.