Skip to content

Commit

Permalink
[TIMOB-7673] Removed pendingAdd children array
Browse files Browse the repository at this point in the history
  • Loading branch information
pec1985 committed Apr 10, 2014
1 parent e6b5774 commit a221ac1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion iphone/Classes/TiViewProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ enum
TiViewProxy *parent;
pthread_rwlock_t childrenLock;
NSMutableArray *children;
NSMutableArray *pendingAdds;
// NSMutableArray *pendingAdds;

#pragma mark Visual components
TiUIView *view;
Expand Down
104 changes: 52 additions & 52 deletions iphone/Classes/TiViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,22 @@ -(NSArray*)children
if (![NSThread isMainThread]) {
__block NSArray* result = nil;
TiThreadPerformOnMainThread(^{
result = [[self children] retain];
result = [children retain];
}, YES);
return [result autorelease];
}
NSArray* copy = nil;

NSLog(@"Before lock");
pthread_rwlock_rdlock(&childrenLock);
if (windowOpened==NO && children==nil && pendingAdds!=nil)
{
copy = [pendingAdds mutableCopy];
}
else {
copy = [children mutableCopy];
}
NSLog(@"After lock");
NSArray* copy = [children mutableCopy];
// if (windowOpened==NO && children==nil && pendingAdds!=nil)
// {
// copy = [pendingAdds mutableCopy];
// }
// else {
// copy = ;
// }
pthread_rwlock_unlock(&childrenLock);
return ((copy != nil) ? [copy autorelease] : [NSMutableArray array]);
}
Expand Down Expand Up @@ -179,20 +181,17 @@ -(void)add:(id)arg
return;
}

if (children==nil)
{
children = [[NSMutableArray alloc] init];
}
if ([NSThread isMainThread])
{
pthread_rwlock_wrlock(&childrenLock);
if (children==nil)
{
children = [[NSMutableArray alloc] initWithObjects:childView,nil];
}
else
{
if(position < 0 || position > [children count]) {
position = [children count];
}
[children insertObject:childView atIndex:position];
if(position < 0 || position > [children count]) {
position = [children count];
}
[children insertObject:childView atIndex:position];
//Turn on clipping because I have children
[self view].clipsToBounds = YES;

Expand Down Expand Up @@ -222,17 +221,17 @@ -(void)add:(id)arg
return;
}
pthread_rwlock_wrlock(&childrenLock);
if (pendingAdds==nil)
{
pendingAdds = [[NSMutableArray arrayWithObject:childView] retain];
}
else
{
// if (pendingAdds==nil)
// {
// pendingAdds = [[NSMutableArray arrayWithObject:childView] retain];
// }
// else
// {
if(position < 0 || position > [children count]) {
position = [pendingAdds count];
position = [children count];
}
[pendingAdds insertObject:childView atIndex:position];
}
[children insertObject:childView atIndex:position];
// }
pthread_rwlock_unlock(&childrenLock);
[childView setParent:self];
}
Expand All @@ -248,7 +247,7 @@ -(void)replaceAt:(id)args
{
ENSURE_SINGLE_ARG(args, NSDictionary);
NSInteger position = [TiUtils intValue:[args objectForKey:@"position"] def:-1];
if(children != nil && position > -1 && [children count] >= position) {
if(children != nil && position > -1 && [children count] > position) {
TiViewProxy *childToRemove = [[children objectAtIndex:position] retain];
[self add:args];
[self remove: childToRemove];
Expand Down Expand Up @@ -278,10 +277,10 @@ -(void)remove:(id)arg
{
[children removeObject:arg];
}
else if ([pendingAdds containsObject:arg])
{
[pendingAdds removeObject:arg];
}
// else if ([pendingAdds containsObject:arg])
// {
// [pendingAdds removeObject:arg];
// }
else
{
pthread_rwlock_unlock(&childrenLock);
Expand Down Expand Up @@ -340,10 +339,10 @@ -(void)removeAllChildren:(id)arg

for (TiViewProxy* child in children)
{
if ([pendingAdds containsObject:child])
{
[pendingAdds removeObject:child];
}
// if ([pendingAdds containsObject:child])
// {
// [pendingAdds removeObject:child];
// }

[child setParent:nil];
[self forgetProxy:child];
Expand Down Expand Up @@ -832,7 +831,7 @@ -(CGFloat)autoWidthForSize:(CGSize)size
CGFloat thisWidth = 0.0;

pthread_rwlock_rdlock(&childrenLock);
NSArray* subproxies = [self children];
NSArray* subproxies = children;
for (TiViewProxy * thisChildProxy in subproxies)
{
if (isHorizontal) {
Expand Down Expand Up @@ -887,7 +886,8 @@ -(CGFloat)autoHeightForSize:(CGSize)size
CGFloat thisHeight = 0.0;

pthread_rwlock_rdlock(&childrenLock);
NSArray* array = windowOpened ? children : pendingAdds;
NSArray* array = children;
// NSArray* array = windowOpened ? children : pendingAdds;

for (TiViewProxy * thisChildProxy in array)
{
Expand Down Expand Up @@ -1101,7 +1101,7 @@ -(TiUIView*)view
[view configurationSet];

pthread_rwlock_rdlock(&childrenLock);
NSArray * childrenArray = [[self children] retain];
NSArray * childrenArray = [children retain];
pthread_rwlock_unlock(&childrenLock);

for (id child in childrenArray)
Expand Down Expand Up @@ -1230,15 +1230,15 @@ -(void)windowWillOpen

pthread_rwlock_unlock(&childrenLock);

if (pendingAdds!=nil)
{
for (id child in pendingAdds)
{
[self add:child];
[child windowWillOpen];
}
RELEASE_TO_NIL(pendingAdds);
}
// if (pendingAdds!=nil)
// {
// for (id child in pendingAdds)
// {
// [self add:child];
// [child windowWillOpen];
// }
// RELEASE_TO_NIL(pendingAdds);
// }
}

-(void)windowDidOpen
Expand Down Expand Up @@ -1456,7 +1456,7 @@ -(void)_initWithProperties:(NSDictionary*)properties

-(void)dealloc
{
RELEASE_TO_NIL(pendingAdds);
// RELEASE_TO_NIL(pendingAdds);
RELEASE_TO_NIL(destroyLock);
pthread_rwlock_destroy(&childrenLock);

Expand Down Expand Up @@ -1525,7 +1525,7 @@ -(void)detachView
}

pthread_rwlock_rdlock(&childrenLock);
[[self children] makeObjectsPerformSelector:@selector(detachView)];
[children makeObjectsPerformSelector:@selector(detachView)];
pthread_rwlock_unlock(&childrenLock);
[destroyLock unlock];
}
Expand Down Expand Up @@ -2846,7 +2846,7 @@ -(void)layoutChildren:(BOOL)optimize

//TODO: This is really expensive, but what can you do? Laying out the child needs the lock again.
pthread_rwlock_rdlock(&childrenLock);
NSArray * childrenArray = [[self children] retain];
NSArray * childrenArray = [children retain];
pthread_rwlock_unlock(&childrenLock);

NSUInteger childCount = [childrenArray count];
Expand Down

0 comments on commit a221ac1

Please sign in to comment.