From 1c35b705eb44e9844bc1d02ac5f095b67ee66cf3 Mon Sep 17 00:00:00 2001 From: Kfir Schindelhaim Date: Fri, 26 Apr 2019 10:11:43 -0700 Subject: [PATCH] Use the cached layout wrapper if it exists Summary: - We cache the layout wrapper, but never used it actually. - This should make the Layout plugin faster. Reviewed By: fabiomassimo Differential Revision: D15046463 fbshipit-source-id: b61f28d9a981e782b76abe78037d37665f7d8ba3 --- .../SKComponentLayoutWrapper.mm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.mm b/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.mm index 215d780b1..a055fc0e9 100644 --- a/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.mm +++ b/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.mm @@ -45,12 +45,21 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(CKComponent *parent, CKCo + (instancetype)newFromRoot:(id)root { const CKComponentLayout layout = [root mountedLayout]; + // Check if there is a cached wrapper. + if (layout.component) { + SKComponentLayoutWrapper *cachedWrapper = objc_getAssociatedObject(layout.component, &kLayoutWrapperKey); + if (cachedWrapper) { + return cachedWrapper; + } + } CKComponentReuseWrapper *reuseWrapper = CKAnalyticsListenerHelpers::GetReusedNodes(layout.component); + // Create a new layout wrapper. SKComponentLayoutWrapper *const wrapper = [[SKComponentLayoutWrapper alloc] initWithLayout:layout position:CGPointMake(0, 0) parentKey:[NSString stringWithFormat: @"%p.", layout.component] reuseWrapper:reuseWrapper]; + // Cache the result. if (layout.component) { objc_setAssociatedObject(layout.component, &kLayoutWrapperKey, wrapper, OBJC_ASSOCIATION_RETAIN_NONATOMIC); }