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