Skip to content

Commit 11c48a4

Browse files
Make ParseModuleCollection initialization not dispatch_async multiple times.
By lifting the `dispatch_async` outside of the module collection enumeration, it allows for fewer local variable caputres, improving perfromance, as well as not requiring multiple flushes of the main dispatch queue to execute.
1 parent 51201d3 commit 11c48a4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Parse/Internal/ParseModule.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ - (NSUInteger)modulesCount {
8181
///--------------------------------------
8282

8383
- (void)parseDidInitializeWithApplicationId:(NSString *)applicationId clientKey:(NSString *)clientKey {
84-
[self enumerateModulesWithBlock:^(id<ParseModule> module, BOOL *stop, BOOL *remove) {
85-
dispatch_async(dispatch_get_main_queue(), ^{
84+
dispatch_async(dispatch_get_main_queue(), ^{
85+
[self enumerateModulesWithBlock:^(id<ParseModule> module, BOOL *stop, BOOL *remove) {
8686
[module parseDidInitializeWithApplicationId:applicationId clientKey:clientKey];
87-
});
88-
}];
87+
}];
88+
});
8989
}
9090

9191
///--------------------------------------

Tests/Unit/ParseModuleUnitTests.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ - (void)testWeakModuleReference {
5353
}
5454

5555
[collection parseDidInitializeWithApplicationId:nil clientKey:nil];
56+
57+
// Run a single runloop tick to trigger the parse initializaiton.
58+
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantPast]];
59+
5660
XCTAssertEqual([collection modulesCount], 0);
5761
}
5862

0 commit comments

Comments
 (0)