mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 19:30:29 +00:00
[ASDisplayNode] Allow display-scheduling method to be called concurrently.
This commit is contained in:
parent
f3696cfef0
commit
fce722b0c8
@ -219,29 +219,41 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
|||||||
|
|
||||||
+ (void)scheduleNodeForRecursiveDisplay:(ASDisplayNode *)node
|
+ (void)scheduleNodeForRecursiveDisplay:(ASDisplayNode *)node
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertMainThread();
|
static ASDN::RecursiveMutex __displaySchedulerLock;
|
||||||
static NSMutableSet *nodesToDisplay = nil;
|
static NSMutableArray *__nodesToDisplay = nil;
|
||||||
static BOOL displayScheduled = NO;
|
static BOOL __displayScheduled = NO;
|
||||||
static ASDN::RecursiveMutex displaySchedulerLock;
|
|
||||||
|
|
||||||
|
BOOL scheduleDisplayPassNow = NO;
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(displaySchedulerLock);
|
ASDN::MutexLocker l(__displaySchedulerLock);
|
||||||
if (!nodesToDisplay) {
|
|
||||||
nodesToDisplay = [[NSMutableSet alloc] init];
|
if (!__nodesToDisplay) {
|
||||||
}
|
__nodesToDisplay = [NSMutableArray array];
|
||||||
[nodesToDisplay addObject:node];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!displayScheduled) {
|
if ([__nodesToDisplay indexOfObjectIdenticalTo:node] == NSNotFound) {
|
||||||
displayScheduled = YES;
|
[__nodesToDisplay addObject:node];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!__displayScheduled) {
|
||||||
|
scheduleDisplayPassNow = YES;
|
||||||
|
__displayScheduled = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scheduleDisplayPassNow) {
|
||||||
// It's essenital that any layout pass that is scheduled during the current
|
// It's essenital that any layout pass that is scheduled during the current
|
||||||
// runloop has a chance to be applied / scheduled, so always perform this after the current runloop.
|
// runloop has a chance to be applied / scheduled, so always perform this after the current runloop.
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
ASDN::MutexLocker l(displaySchedulerLock);
|
NSArray *displayingNodes = nil;
|
||||||
displayScheduled = NO;
|
// Create a lock scope. Snatch the waiting nodes, let the next batch create a new container.
|
||||||
NSSet *displayingNodes = [nodesToDisplay copy];
|
{
|
||||||
|
ASDN::MutexLocker l(__displaySchedulerLock);
|
||||||
|
displayingNodes = [__nodesToDisplay copy];
|
||||||
|
__nodesToDisplay = nil;
|
||||||
|
__displayScheduled = NO;
|
||||||
|
}
|
||||||
CFAbsoluteTime timestamp = CFAbsoluteTimeGetCurrent();
|
CFAbsoluteTime timestamp = CFAbsoluteTimeGetCurrent();
|
||||||
nodesToDisplay = nil;
|
|
||||||
for (ASDisplayNode *node in displayingNodes) {
|
for (ASDisplayNode *node in displayingNodes) {
|
||||||
[node __recursivelyTriggerDisplayAndBlock:NO];
|
[node __recursivelyTriggerDisplayAndBlock:NO];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -168,7 +168,6 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
|||||||
for (NSUInteger j = 0; j < nodes.count && j < indexPaths.count; j += kASDataControllerSizingCountPerProcessor) {
|
for (NSUInteger j = 0; j < nodes.count && j < indexPaths.count; j += kASDataControllerSizingCountPerProcessor) {
|
||||||
NSInteger batchCount = MIN(kASDataControllerSizingCountPerProcessor, indexPaths.count - j);
|
NSInteger batchCount = MIN(kASDataControllerSizingCountPerProcessor, indexPaths.count - j);
|
||||||
|
|
||||||
|
|
||||||
dispatch_block_t allocationBlock = ^{
|
dispatch_block_t allocationBlock = ^{
|
||||||
for (NSUInteger k = j; k < j + batchCount; k++) {
|
for (NSUInteger k = j; k < j + batchCount; k++) {
|
||||||
ASCellNodeBlock cellBlock = nodes[k];
|
ASCellNodeBlock cellBlock = nodes[k];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user