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
- (void)insertSections:(NSIndexSet *)indexSet {
NSMutableArray *sectionArray = [[NSMutableArray alloc] initWithCapacity:indexSet.count];
for (NSUInteger i = 0; i < indexSet.count; i++) {
NSUInteger rowNum = [_dataSource dataController:self rowsInSection:i];
NSMutableArray *rows = [[NSMutableArray alloc] initWithCapacity:rowNum];
__block int nodeTotalCnt = 0;
NSMutableArray *nodeCounts = [NSMutableArray arrayWithCapacity:indexSet.count];
[indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
NSUInteger cnt = [_dataSource dataController:self rowsInSection:idx];
[nodeCounts addObject:@(cnt)];
nodeTotalCnt += cnt;
}];
for (NSUInteger j = 0; j < rowNum; j++) {
ASCellNode *node = [_dataSource dataController:self nodeAtIndexPath:[NSIndexPath indexPathForItem:j inSection:i]];
[rows addObject:node];
}
[sectionArray addObject:rows];
NSMutableArray *nodes = [NSMutableArray arrayWithCapacity:nodeTotalCnt];
NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:nodeTotalCnt];
__block NSUInteger idx = 0;
[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], ^{
[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);
}];
[self _insertNodes:nodes atIndexPaths:indexPaths];
});
}

View File

@@ -57,7 +57,8 @@ static const CGFloat kASFlowLayoutControllerRefreshingThreshold = 0.3;
__block int cnt = 0;
[indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
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++) {
v.push_back([nodes[i] CGSizeValue]);