From b098d8079671816375264bca6df1adc7fcf219a5 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Mon, 29 Feb 2016 11:36:48 -0800 Subject: [PATCH] Performance improvements in ASDataController based on @Adlai-Holler comments in #1288 --- AsyncDisplayKit/Details/ASDataController.mm | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/AsyncDisplayKit/Details/ASDataController.mm b/AsyncDisplayKit/Details/ASDataController.mm index 35971099..7c3bf0e8 100644 --- a/AsyncDisplayKit/Details/ASDataController.mm +++ b/AsyncDisplayKit/Details/ASDataController.mm @@ -227,9 +227,9 @@ static void *kASSizingQueueContext = &kASSizingQueueContext; if (completionBlock) { NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:nodeCount]; - [contexts enumerateObjectsUsingBlock:^(ASIndexedNodeContext * _Nonnull context, NSUInteger idx, BOOL * _Nonnull stop) { + for (ASIndexedNodeContext *context in contexts) { [indexPaths addObject:context.indexPath]; - }]; + } completionBlock(allocatedNodes, indexPaths); } @@ -773,14 +773,13 @@ static void *kASSizingQueueContext = &kASSizingQueueContext; LOG(@"Edit Command - insertRows: %@", indexPaths); [_editingTransactionQueue waitUntilAllOperationsAreFinished]; - + + // sort indexPath to avoid messing up the index when inserting in several batches + NSArray *sortedIndexPaths = [indexPaths sortedArrayUsingSelector:@selector(compare:)]; + NSMutableArray *contexts = [[NSMutableArray alloc] initWithCapacity:indexPaths.count]; + [self accessDataSourceWithBlock:^{ - // sort indexPath to avoid messing up the index when inserting in several batches - NSArray *sortedIndexPaths = [indexPaths sortedArrayUsingSelector:@selector(compare:)]; - NSMutableArray *contexts = [[NSMutableArray alloc] initWithCapacity:indexPaths.count]; - - for (NSUInteger i = 0; i < sortedIndexPaths.count; i++) { - NSIndexPath *indexPath = sortedIndexPaths[i]; + for (NSIndexPath *indexPath in sortedIndexPaths) { ASCellNodeBlock nodeBlock = [_dataSource dataController:self nodeBlockAtIndexPath:indexPath]; ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind:ASDataControllerRowNodeKind atIndexPath:indexPath]; [contexts addObject:[[ASIndexedNodeContext alloc] initWithNodeBlock:nodeBlock