-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[ASDisplayNode+Layout] Add check for orphaned nodes after layout transition to clean up. #336
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@appleguy Dang this is an annoying issue.
Since this is a reasonably hot code path, let's use [NSHashTable hashTableWithOptions:NSHashTableObjectPointerPersonality]
to avoid needless -hash
and -isEqual:
and then let's land.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a better place to remove orphaned nodes. However, I'm willing to accept this approach.
In the near future, we should aim to address the root cause, which I believe is due to the fact that ASLayoutTransition
accepts it previous layout in the initializer, instead of at commit time (i.e -commitTransition
). It means that the transition assumes that if it's allowed to proceed on main, the previous layout remains valid which is not true if there was layout pass triggered on main via -setNeedsLayout
.
0875e09
to
4fc0dc0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Source/ASDisplayNode+Layout.mm
Outdated
NSArray<ASDisplayNode *> *subnodes = [self subnodes]; | ||
NSHashTable<ASDisplayNode *> *currentSubnodes = | ||
[[NSHashTable alloc] initWithOptions:NSHashTableObjectPointerPersonality | ||
capacity:subnodes.count]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally optional, you can do auto currentSubnodes = [[NSHashTable<ASDisplayNode *> alloc]…]
to save some characters.
…sition to clean up. It is rare that this code has any effect, but I've discovered a case in which it occurs. This task tracks moving this code to a DEBUG-only assertion: #335
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Diff was amended to be more readable.) Awesome!
auto currentSubnodes = [[NSHashTable alloc] initWithOptions:NSHashTableObjectPointerPersonality | ||
capacity:subnodes.count]; | ||
auto layoutSubnodes = [[NSHashTable alloc] initWithOptions:NSHashTableObjectPointerPersonality | ||
capacity:sublayouts.count];; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except this double-semicolon =)
…sition to clean up. (TextureGroup#336) It is rare that this code has any effect, but I've discovered a case in which it occurs. This task tracks moving this code to a DEBUG-only assertion: TextureGroup#335
It is rare that this code has any effect, but I've discovered a case in which it occurs.
This task tracks moving this code to a DEBUG-only assertion: #335