If a layout has no sublayouts, don't bother initializing its rect table (#394)

This commit is contained in:
Huy Nguyen 2017-06-29 15:09:49 +01:00 committed by GitHub
parent f7a6b7ae84
commit 23ee9de615

View File

@ -124,9 +124,11 @@ static std::atomic_bool static_retainsSublayoutLayoutElements = ATOMIC_VAR_INIT(
_sublayouts = sublayouts != nil ? [sublayouts copy] : @[];
_elementToRectTable = [ASRectTable rectTableForWeakObjectPointers];
for (ASLayout *layout in sublayouts) {
[_elementToRectTable setRect:layout.frame forKey:layout.layoutElement];
if (_sublayouts.count > 0) {
_elementToRectTable = [ASRectTable rectTableForWeakObjectPointers];
for (ASLayout *layout in sublayouts) {
[_elementToRectTable setRect:layout.frame forKey:layout.layoutElement];
}
}
_flattened = NO;
@ -251,7 +253,7 @@ static std::atomic_bool static_retainsSublayoutLayoutElements = ATOMIC_VAR_INIT(
- (CGRect)frameForElement:(id<ASLayoutElement>)layoutElement
{
return [_elementToRectTable rectForKey:layoutElement];
return _elementToRectTable ? [_elementToRectTable rectForKey:layoutElement] : CGRectNull;
}
- (CGRect)frame