Skip to content

Commit 385cc74

Browse files
committed
Remove redundant task creation for results of continuations.
1 parent 39ab7b8 commit 385cc74

File tree

11 files changed

+32
-34
lines changed

11 files changed

+32
-34
lines changed

Parse/Internal/LocalDataStore/OfflineQueryLogic/PFOfflineQueryLogic.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "PFOfflineQueryLogic.h"
1111

1212
#import <Bolts/BFTask.h>
13+
#import <Bolts/BFExecutor.h>
1314

1415
#import "PFACL.h"
1516
#import "PFAssert.h"
@@ -695,7 +696,7 @@ - (BFTask *)fetchIncludeAsync:(NSString *)include
695696
rest = [[parts subarrayWithRange:range] componentsJoinedByString:@"."];
696697
}
697698

698-
return [[[BFTask taskWithResult:nil] continueWithBlock:^id(BFTask *task) {
699+
return [[BFTask taskFromExecutor:[BFExecutor defaultExecutor] withBlock:^id{
699700
if ([container isKindOfClass:[PFObject class]]) {
700701
BFTask *fetchTask = [self fetchIncludeAsync:nil container:container database:database];
701702
return [fetchTask continueWithSuccessBlock:^id(BFTask *task) {

Parse/Internal/LocalDataStore/OfflineStore/PFOfflineStore.m

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ - (BFTask *)fetchObjectLocallyAsync:(PFObject *)object database:(PFSQLiteDatabas
143143
// The object has been fetched from offline store, so any data that's in there
144144
// is already reflected in the in-memory version. There's nothing more to do.
145145
return [fetchTask continueWithBlock:^id(BFTask *task) {
146-
return [BFTask taskWithResult:[task.result weakObject]];
146+
return [task.result weakObject];
147147
}];
148148
}
149149

150150
// Put a placeholder so that anyone else who attempts to fetch this object will just
151151
// wait for this call to finish doing it.
152152
[self.fetchedObjects setObject:[tcs.task continueWithBlock:^id(BFTask *task) {
153-
return [BFTask taskWithResult:[PFWeakValue valueWithWeakObject:task.result]];
153+
return [PFWeakValue valueWithWeakObject:task.result];
154154
}] forKey:object];
155155
uuidTask = [self.objectToUUIDMap objectForKey:object];
156156
}
@@ -277,7 +277,7 @@ - (BFTask *)fetchObjectLocallyAsync:(PFObject *)object database:(PFSQLiteDatabas
277277
return [[BFTask taskForCompletionOfAllTasks:objectValues] continueWithSuccessBlock:^id(BFTask *task) {
278278
PFDecoder *decoder = [PFOfflineDecoder decoderWithOfflineObjects:offlineObjects];
279279
[object mergeFromRESTDictionary:parsedJson withDecoder:decoder];
280-
return [BFTask taskWithResult:nil];
280+
return nil;
281281
}];
282282
}] continueWithBlock:^id(BFTask *task) {
283283
if (task.isCancelled) {
@@ -353,7 +353,7 @@ - (BFTask *)saveObjectLocallyAsync:(PFObject *)object
353353
NSString *uuid = task.result;
354354
if (uuid == nil) {
355355
// The root object was never stored in offline store, so nothing unpin.
356-
return [BFTask taskWithResult:nil];
356+
return nil;
357357
}
358358

359359
// Delete all objects locally corresponding to the key we're trying to use in case it was
@@ -531,14 +531,14 @@ - (BFTask *)findAsyncForQueryState:(PFQueryState *)queryState
531531
return [self fetchObjectLocallyAsync:object database:database];
532532
}] continueWithSuccessBlock:^id(BFTask *task) {
533533
if (!object.dataAvailable) {
534-
return [BFTask taskWithResult:@NO];
534+
return @NO;
535535
}
536536
return matcherBlock(object, database);
537537
}] continueWithSuccessBlock:^id(BFTask *task) {
538538
if ([task.result boolValue]) {
539539
[mutableResults addObject:object];
540540
}
541-
return [BFTask taskWithResult:nil];
541+
return nil;
542542
}];
543543
}
544544
[result close];
@@ -588,9 +588,9 @@ - (BFTask *)updateDataForObjectAsync:(PFObject *)object {
588588
if (task.error != nil) {
589589
// Catch CACHE_MISS errors and ignore them.
590590
if (task.error.code == kPFErrorCacheMiss) {
591-
return [BFTask taskWithResult:nil];
591+
return nil;
592592
}
593-
return [BFTask taskWithResult:[task.result weakObject]];
593+
return [task.result weakObject];
594594
}
595595

596596
return [self _performDatabaseTransactionAsyncWithBlock:^BFTask *(PFSQLiteDatabase *database) {
@@ -751,7 +751,7 @@ - (BFTask *)unpinObjectAsync:(PFObject *)object {
751751
NSString *uuid = task.result;
752752
if (!uuid) {
753753
// The root object was never stored in the offline store, so nothing to unpin.
754-
return [BFTask taskWithResult:nil];
754+
return nil;
755755
}
756756
return [self _unpinKeyAsync:uuid];
757757
}];
@@ -798,7 +798,7 @@ - (BFTask *)_unpinKeyAsync:(NSString *)key database:(PFSQLiteDatabase *)database
798798
}
799799
}
800800
}
801-
return [BFTask taskWithResult:nil];
801+
return nil;
802802
}];
803803
}
804804

@@ -861,7 +861,7 @@ - (BFTask *)getOrCreateUUIDAsyncForObject:(PFObject *)object
861861
[[database executeSQLAsync:query
862862
withArgumentsInArray:@[ newUUID, [object parseClassName]]] continueWithSuccessBlock:^id(BFTask *task) {
863863
[tcs setResult:newUUID];
864-
return [BFTask taskWithResult:nil];
864+
return nil;
865865
}];
866866

867867
return tcs.task;

Parse/Internal/LocalDataStore/SQLite/PFSQLiteDatabase.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ - (BFTask *)openAsync {
124124
}
125125

126126
self.database = db;
127-
return [BFTask taskWithResult:nil];
127+
return nil;
128128
}];
129129
}
130130

@@ -242,7 +242,7 @@ - (BFTask *)executeSQLAsync:(NSString *)sql withArgumentsInArray:(NSArray *)args
242242

243243
switch (sqliteResultCode) {
244244
case SQLITE_DONE: {
245-
return [BFTask taskWithResult:nil];
245+
return nil;
246246
}
247247
case SQLITE_ROW: {
248248
NSError *error = [self _errorWithErrorCode:PFSQLiteDatabaseInvalidSQL

Parse/Internal/Object/Controller/OfflineController/PFOfflineObjectController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ - (BFTask *)processFetchResultAsync:(NSDictionary *)result forObject:(PFObject *
5757
// Catch CACHE_MISS and ignore it.
5858
if ([task.error.domain isEqualToString:PFParseErrorDomain] &&
5959
task.error.code == kPFErrorCacheMiss) {
60-
return [BFTask taskWithResult:nil];
60+
return nil;
6161
}
6262
return task;
6363
}];

Parse/Internal/PFCommandCache.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ - (BFTask *)_cleanupDiskCacheWithRequiredFreeSize:(NSUInteger)requiredSize {
257257
}
258258
}
259259

260-
return [BFTask taskWithResult:nil];
260+
return nil;
261261
}];
262262
}
263263

Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ - (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {
101101
return [BFTask taskWithResult:@YES];
102102
}
103103
return [BFTask taskFromExecutor:[BFExecutor defaultPriorityBackgroundExecutor] withBlock:^id {
104-
return [BFTask taskWithResult:@([provider restoreAuthenticationWithAuthData:authData])];
104+
return @([provider restoreAuthenticationWithAuthData:authData]);
105105
}];
106106
}
107107

@@ -159,7 +159,7 @@ - (BFTask *)logInUserAsyncWithAuthType:(NSString *)authType authData:(NSDictiona
159159
}
160160
}
161161

162-
return [BFTask taskWithResult:currentUser];
162+
return currentUser;
163163
}];
164164
}
165165
}

Parse/Internal/User/CurrentUserController/PFCurrentUserController.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,9 @@ - (BFTask *)_loadCurrentUserFromDiskAsync {
224224
task = [[query findObjectsInBackground] continueWithSuccessBlock:^id(BFTask *task) {
225225
NSArray *results = task.result;
226226
if ([results count] == 1) {
227-
return [BFTask taskWithResult:results.firstObject];
227+
return results.firstObject;
228228
} else if ([results count] != 0) {
229-
return [[PFObject unpinAllObjectsInBackgroundWithName:PFUserCurrentUserPinName]
230-
continueWithSuccessResult:nil];
229+
return [[PFObject unpinAllObjectsInBackgroundWithName:PFUserCurrentUserPinName] continueWithSuccessResult:nil];
231230
}
232231

233232
// Backward compatibility if we previously have non-LDS currentUser.

Parse/PFFile.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ - (BFTask *)_uploadAsyncWithProgressBlock:(PFProgressBlock)progressBlock {
321321
return [self.taskQueue enqueue:^id(BFTask *task) {
322322
if (!self.dirty) {
323323
[self _performProgressBlockAsync:progressBlock withProgress:100];
324-
return [BFTask taskWithResult:nil];
324+
return nil;
325325
}
326326

327327
return [self _uploadFileAsyncWithSessionToken:sessionToken
@@ -388,7 +388,7 @@ - (BFTask *)_downloadAsyncWithProgressBlock:(PFProgressBlock)progressBlock {
388388
@strongify(self);
389389
if (self.dataAvailable) {
390390
[self _performProgressBlockAsync:progressBlock withProgress:100];
391-
return [BFTask taskWithResult:nil];
391+
return nil;
392392
}
393393

394394
PFFileController *controller = [[self class] fileController];

Parse/PFObject.m

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ - (BFTask *)_enqueueSaveEventuallyWithChildren:(BOOL)saveChildren {
10701070
@synchronized (lock) {
10711071
[self _objectWillSave];
10721072
if (![self isDirty:NO]) {
1073-
return [BFTask taskWithResult:@YES];
1073+
return @YES;
10741074
}
10751075
}
10761076

@@ -1332,11 +1332,9 @@ - (void)_mergeFromServerWithResult:(NSDictionary *)result decoder:(PFDecoder *)d
13321332
// to add special actions after operations.
13331333

13341334
- (BFTask *)handleSaveResultAsync:(NSDictionary *)result {
1335-
BFTask *task = [BFTask taskWithResult:nil];
1336-
13371335
NSDictionary *fetchedObjects = [self _collectFetchedObjects];
13381336

1339-
[task continueWithBlock:^id(BFTask *task) {
1337+
BFTask *task = [BFTask taskFromExecutor:[BFExecutor defaultExecutor] withBlock:^id{
13401338
PFKnownParseObjectDecoder *decoder = [PFKnownParseObjectDecoder decoderWithFetchedObjects:fetchedObjects];
13411339
@synchronized (self.lock) {
13421340
// TODO (hallucinogen): t5611821 we need to make mergeAfterSave that accepts decoder and operationBeforeSave
@@ -1357,7 +1355,7 @@ - (BFTask *)handleSaveResultAsync:(NSDictionary *)result {
13571355
if (self.saveDelegate) {
13581356
[self.saveDelegate invoke:self error:nil];
13591357
}
1360-
return [BFTask taskWithResult:@(!!result)];
1358+
return @(result != nil);
13611359
}
13621360
}];
13631361
}
@@ -1388,7 +1386,7 @@ - (BFTask *)saveAsync:(BFTask *)toAwait {
13881386
}] continueWithBlock:^id(BFTask *task) {
13891387
@synchronized (lock) {
13901388
if (![self isDirty:YES]) {
1391-
return [BFTask taskWithResult:@YES];
1389+
return @YES;
13921390
}
13931391

13941392
[self _objectWillSave];

Parse/PFQuery.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ - (BFTask *)_getObjectWithIdAsync:(NSString *)objectId cachePolicy:(PFCachePolic
758758
return [BFTask taskWithError:[PFQueryUtilities objectNotFoundError]];
759759
}
760760

761-
return [BFTask taskWithResult:objects.lastObject];
761+
return objects.lastObject;
762762
}];
763763
}
764764

@@ -904,7 +904,7 @@ - (BFTask *)_getFirstObjectAsyncWithCachePolicy:(PFCachePolicy)cachePolicy after
904904
return [BFTask taskWithError:[PFQueryUtilities objectNotFoundError]];
905905
}
906906

907-
return [BFTask taskWithResult:objects.lastObject];
907+
return objects.lastObject;
908908
}];
909909
}
910910

Parse/PFUser.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ - (BFTask *)_handleServiceLoginCommandResult:(PFCommandResult *)result {
240240
return self;
241241
}];
242242
}
243-
return [BFTask taskWithResult:self];
243+
return self;
244244
}
245245
}];
246246
}];
@@ -699,7 +699,7 @@ + (BFTask *)_upgradeToRevocableSessionInBackground {
699699

700700
// Bail-out early if session token is already revocable.
701701
if ([PFSessionUtilities isSessionTokenRevocable:sessionToken]) {
702-
return [BFTask taskWithResult:currentUser];
702+
return currentUser;
703703
}
704704
return [currentUser _upgradeToRevocableSessionInBackground];
705705
}];
@@ -718,7 +718,7 @@ - (BFTask *)_upgradeToRevocableSessionInBackground {
718718

719719
// Check session token here as well, to make sure we didn't upgrade the token in between.
720720
if ([PFSessionUtilities isSessionTokenRevocable:token]) {
721-
return [BFTask taskWithResult:self];
721+
return self;
722722
}
723723

724724
PFRESTCommand *command = [PFRESTUserCommand upgradeToRevocableSessionCommandWithSessionToken:token];

0 commit comments

Comments
 (0)