Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: optimize relayout queue #3751

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 71 additions & 1 deletion iphone/Classes/TiLayoutQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,73 @@
CFRunLoopTimerRef layoutTimer = NULL;
pthread_mutex_t layoutMutex;

void allNodes(NSMutableArray** array, TiViewProxy* tivp) {
if([tivp.children count] > 0) {
for (TiViewProxy* p in tivp.children) {
allNodes(array, p);
}
}
return [(NSMutableArray*)(*array) addObject:tivp];
}


NSMutableArray* getAllNodesOfProxy(NSArray* array) {
NSMutableArray* all = [[NSMutableArray alloc] init];
for (TiViewProxy* proxy in array) {
NSMutableArray* allChildrenOfProxy = [[NSMutableArray alloc] init];
[allChildrenOfProxy addObject:proxy];
allNodes(&allChildrenOfProxy, proxy);
[all addObject:allChildrenOfProxy];
}

return all;
}


NSArray* isInSameTree(NSArray* needs) {
NSMutableArray* alltrees = getAllNodesOfProxy(needs);
int count = [alltrees count];
NSMutableArray* indexes = [[NSMutableArray alloc] initWithCapacity:count];

for (int i = 0; i < count; i++) {
for (int j = 0; j < count; j++) {
if (i != j) {
if([[alltrees objectAtIndex:j] containsObject:[[alltrees objectAtIndex:i] objectAtIndex:0]] ) {
[indexes addObject:[NSNumber numberWithInt:i]];
continue;
}
}
}
}

for(int i = 0; i < [indexes count]; i++) {
int tmp = [[indexes objectAtIndex:i] integerValue];
for (int j = 0; j < [indexes count]; j++) {
if (i != j) {
if([[indexes objectAtIndex:j] integerValue] == tmp) {
[indexes removeObjectAtIndex:j];
}
}
}
}

NSMutableIndexSet* indexSet = [[NSMutableIndexSet alloc] init];
for (NSNumber* num in indexes) {
[indexSet addIndex:[num integerValue]];
}
[alltrees removeObjectsAtIndexes:indexSet];
[indexes removeAllObjects];

for(NSMutableArray* a in alltrees) {
//tmp use indexes,avoid alloc new array.
[indexes addObject:[a objectAtIndex:0]];
}

[alltrees release];

return indexes;
}


void performLayoutRefresh(CFRunLoopTimerRef timer, void *info)
{
Expand All @@ -36,11 +103,14 @@ void performLayoutRefresh(CFRunLoopTimerRef timer, void *info)
layoutTimer = NULL;
}

// add push req for this optimization
localLayoutArray = isInSameTree(localLayoutArray);

pthread_mutex_unlock(&layoutMutex);

for (TiViewProxy *thisProxy in localLayoutArray)
{
[TiLayoutQueue layoutProxy:thisProxy];
[TiLayoutQueue layoutProxy:thisProxy];
}

RELEASE_TO_NIL(localLayoutArray);
Expand Down