Fix passing wrong constrained size to nodes

In _layoutNodesFromContexts:ofKind:completion: we pass the full array of contexts to _layoutNodes:fromContexts:atIndexesOfRange:ofKind: but for nodes we pass a subarray of nodes instead based on the batchCount. As batchRange we always start from 0 to batchCount. We now use the same indexes that we use to create the subarray of nodes to get a subarray of contexts that we pass to _layoutNodes:fromContexts:atIndexesOfRange:ofKind:.
This commit is contained in:
Michael Schneider
2016-05-13 21:02:11 +02:00
parent 0bef0d09e7
commit 7d902d98c9

View File

@@ -191,14 +191,16 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
for (NSUInteger j = 0; j < nodeCount; j += kASDataControllerSizingCountPerProcessor) {
NSInteger batchCount = MIN(kASDataControllerSizingCountPerProcessor, nodeCount - j);
__block NSArray *subarray;
// Get subcontexts for the range of nodes that will be allocated
NSArray *subcontexts = [contexts subarrayWithRange:NSMakeRange(j, batchCount)];
// Allocate nodes concurrently.
__block NSArray *subarray;
dispatch_block_t allocationBlock = ^{
__strong ASCellNode **allocatedNodeBuffer = (__strong ASCellNode **)calloc(batchCount, sizeof(ASCellNode *));
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_apply(batchCount, queue, ^(size_t i) {
unsigned long k = j + i;
ASCellNode *node = [contexts[k] allocateNode];
ASCellNode *node = [subcontexts[i] allocateNode];
if (node == nil) {
ASDisplayNodeAssertNotNil(node, @"Node block created nil node; %@, %@", self, self.dataSource);
node = [[ASCellNode alloc] init]; // Fallback to avoid crash for production apps.
@@ -225,11 +227,11 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
[self _layoutNodes:subarray fromContexts:contexts atIndexesOfRange:batchRange ofKind:kind];
[self _layoutNodes:subarray fromContexts:subcontexts atIndexesOfRange:batchRange ofKind:kind];
} else {
allocationBlock();
[_mainSerialQueue performBlockOnMainThread:^{
[self _layoutNodes:subarray fromContexts:contexts atIndexesOfRange:batchRange ofKind:kind];
[self _layoutNodes:subarray fromContexts:subcontexts atIndexesOfRange:batchRange ofKind:kind];
}];
}