From dc7f67c478dd0b32882d7574d0ce23629e880474 Mon Sep 17 00:00:00 2001 From: Eric Horacek Date: Thu, 5 May 2016 23:56:21 -0700 Subject: [PATCH] Populate more aggresively --- .../Details/ASCollectionDataController.mm | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/AsyncDisplayKit/Details/ASCollectionDataController.mm b/AsyncDisplayKit/Details/ASCollectionDataController.mm index 6531a2ff60..9b4e3bddcd 100644 --- a/AsyncDisplayKit/Details/ASCollectionDataController.mm +++ b/AsyncDisplayKit/Details/ASCollectionDataController.mm @@ -161,9 +161,7 @@ for (NSString *kind in [self supplementaryKinds]) { LOG(@"Populating elements of kind: %@, for index paths: %@", kind, indexPaths); NSMutableArray *contexts = [NSMutableArray array]; - for (NSIndexPath *indexPath in indexPaths) { - [self _populateSupplementaryNodeOfKind:kind atIndexPath:indexPath mutableContexts:contexts]; - } + [self _populateSupplementaryNodesOfKind:kind atIndexPaths:indexPaths mutableContexts:contexts]; _pendingContexts[kind] = contexts; } } @@ -190,9 +188,7 @@ { for (NSString *kind in [self supplementaryKinds]) { NSMutableArray *contexts = [NSMutableArray array]; - for (NSIndexPath *indexPath in indexPaths) { - [self _populateSupplementaryNodeOfKind:kind atIndexPath:indexPath mutableContexts:contexts]; - } + [self _populateSupplementaryNodesOfKind:kind atIndexPaths:indexPaths mutableContexts:contexts]; _pendingContexts[kind] = contexts; } } @@ -245,6 +241,23 @@ }]; } +- (void)_populateSupplementaryNodesOfKind:(NSString *)kind atIndexPaths:(NSArray *)indexPaths mutableContexts:(NSMutableArray *)contexts +{ + NSMutableIndexSet *sections = [NSMutableIndexSet indexSet]; + for (NSIndexPath *indexPath in indexPaths) { + [sections addIndex:indexPath.section]; + } + + [sections enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { + NSUInteger rowNum = [self.collectionDataSource dataController:self supplementaryNodesOfKind:kind inSection:idx]; + NSIndexPath *sectionIndex = [[NSIndexPath alloc] initWithIndex:idx]; + for (NSUInteger i = 0; i < rowNum; i++) { + NSIndexPath *indexPath = [sectionIndex indexPathByAddingIndex:i]; + [self _populateSupplementaryNodeOfKind:kind atIndexPath:indexPath mutableContexts:contexts]; + } + }]; +} + - (void)_populateSupplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath mutableContexts:(NSMutableArray *)contexts { ASCellNodeBlock supplementaryCellBlock;