From 23ee9de615a58a85e489048ff52ca659f0dd68a7 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Thu, 29 Jun 2017 15:09:49 +0100 Subject: [PATCH] If a layout has no sublayouts, don't bother initializing its rect table (#394) --- Source/Layout/ASLayout.mm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/Layout/ASLayout.mm b/Source/Layout/ASLayout.mm index 2bd93f2ce9..7668dd0408 100644 --- a/Source/Layout/ASLayout.mm +++ b/Source/Layout/ASLayout.mm @@ -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)layoutElement { - return [_elementToRectTable rectForKey:layoutElement]; + return _elementToRectTable ? [_elementToRectTable rectForKey:layoutElement] : CGRectNull; } - (CGRect)frame