From 631acb0d2b57cecd857a9c589b10f458a17be1f6 Mon Sep 17 00:00:00 2001 From: Richard Ross Date: Thu, 17 Dec 2015 14:31:34 -0800 Subject: [PATCH] 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. --- Parse/Internal/ParseModule.m | 8 ++++---- Tests/Unit/ParseModuleUnitTests.m | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Parse/Internal/ParseModule.m b/Parse/Internal/ParseModule.m index f7a42c5a1..bc8f97227 100644 --- a/Parse/Internal/ParseModule.m +++ b/Parse/Internal/ParseModule.m @@ -81,11 +81,11 @@ - (NSUInteger)modulesCount { ///-------------------------------------- - (void)parseDidInitializeWithApplicationId:(NSString *)applicationId clientKey:(NSString *)clientKey { - [self enumerateModulesWithBlock:^(id module, BOOL *stop, BOOL *remove) { - dispatch_async(dispatch_get_main_queue(), ^{ + dispatch_async(dispatch_get_main_queue(), ^{ + [self enumerateModulesWithBlock:^(id module, BOOL *stop, BOOL *remove) { [module parseDidInitializeWithApplicationId:applicationId clientKey:clientKey]; - }); - }]; + }]; + }); } ///-------------------------------------- diff --git a/Tests/Unit/ParseModuleUnitTests.m b/Tests/Unit/ParseModuleUnitTests.m index e547229ef..a649947f8 100644 --- a/Tests/Unit/ParseModuleUnitTests.m +++ b/Tests/Unit/ParseModuleUnitTests.m @@ -53,6 +53,10 @@ - (void)testWeakModuleReference { } [collection parseDidInitializeWithApplicationId:nil clientKey:nil]; + + // Run a single runloop tick to trigger the parse initializaiton. + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantPast]]; + XCTAssertEqual([collection modulesCount], 0); }