This commit is contained in:
Li Tan
2014-12-18 13:58:44 -08:00
parent 3e6436245d
commit e799ed9ea4
2 changed files with 30 additions and 11 deletions

View File

@@ -205,22 +205,40 @@ static void *kASDataUpdatingQueueContext = &kASDataUpdatingQueueContext;
#pragma mark - Data Update #pragma mark - Data Update
- (void)insertSections:(NSIndexSet *)indexSet { - (void)insertSections:(NSIndexSet *)indexSet {
NSMutableArray *sectionArray = [[NSMutableArray alloc] initWithCapacity:indexSet.count]; __block int nodeTotalCnt = 0;
for (NSUInteger i = 0; i < indexSet.count; i++) { NSMutableArray *nodeCounts = [NSMutableArray arrayWithCapacity:indexSet.count];
NSUInteger rowNum = [_dataSource dataController:self rowsInSection:i]; [indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
NSMutableArray *rows = [[NSMutableArray alloc] initWithCapacity:rowNum]; NSUInteger cnt = [_dataSource dataController:self rowsInSection:idx];
[nodeCounts addObject:@(cnt)];
nodeTotalCnt += cnt;
}];
for (NSUInteger j = 0; j < rowNum; j++) { NSMutableArray *nodes = [NSMutableArray arrayWithCapacity:nodeTotalCnt];
ASCellNode *node = [_dataSource dataController:self nodeAtIndexPath:[NSIndexPath indexPathForItem:j inSection:i]]; NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:nodeTotalCnt];
[rows addObject:node];
} __block NSUInteger idx = 0;
[sectionArray addObject:rows]; [indexSet enumerateIndexesUsingBlock:^(NSUInteger sectionIdx, BOOL *stop) {
NSUInteger cnt = [nodeCounts[idx++] unsignedIntegerValue];
for (int i = 0; i < cnt; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:sectionIdx];
[indexPaths addObject:indexPath];
ASCellNode *node = [_dataSource dataController:self nodeAtIndexPath:indexPath];
[nodes addObject:node];
} }
}];
dispatch_async([[self class] sizingQueue], ^{ dispatch_async([[self class] sizingQueue], ^{
[self asyncUpdateDataWithBlock:^{ [self syncUpdateDataWithBlock:^{
NSMutableArray *sectionArray = [NSMutableArray arrayWithCapacity:indexSet.count];
for (NSUInteger i = 0; i < indexSet.count; i++) {
[sectionArray addObject:[NSMutableArray array]];
}
INSERT_SECTIONS(_nodes , indexSet, sectionArray); INSERT_SECTIONS(_nodes , indexSet, sectionArray);
}]; }];
[self _insertNodes:nodes atIndexPaths:indexPaths];
}); });
} }

View File

@@ -57,7 +57,8 @@ static const CGFloat kASFlowLayoutControllerRefreshingThreshold = 0.3;
__block int cnt = 0; __block int cnt = 0;
[indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { [indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
NSArray *nodes = sections[cnt++]; NSArray *nodes = sections[cnt++];
std::vector<CGSize> v(nodes.count); std::vector<CGSize> v;
v.reserve(nodes.count);
for (int i = 0; i < nodes.count; i++) { for (int i = 0; i < nodes.count; i++) {
v.push_back([nodes[i] CGSizeValue]); v.push_back([nodes[i] CGSizeValue]);