From df6bec54272f23c1cb828bcba847c65fb5b40a54 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Tue, 27 Feb 2024 05:52:51 -0800 Subject: [PATCH] Optimize RCTUIManager to avoid too many calls to viewForReactTag Summary: This change fixes a couple of issues within the RCTUIManager: * it calls the right method in the `super` branches (although they should neve be executed) * it invert the call order between the `_registry` and the `uiManager` to avoid extra calls into the `viewForReactTag`. ## Changelog: [Internal] - Use the right method in super and invert the order of where we search for views. ## Facebook: See S397861 and T180527210 for more information. Reviewed By: javache Differential Revision: D54246220 fbshipit-source-id: 1c7503ad3e80cf50ecc016a984ca180a19b73cc0 --- packages/react-native/React/Modules/RCTUIManager.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/react-native/React/Modules/RCTUIManager.m b/packages/react-native/React/Modules/RCTUIManager.m index 04e223b9424..71c4c669d3a 100644 --- a/packages/react-native/React/Modules/RCTUIManager.m +++ b/packages/react-native/React/Modules/RCTUIManager.m @@ -1674,8 +1674,8 @@ static UIView *_jsResponder; { self = [super init]; if (self) { - self->_uiManager = uiManager; - self->_registry = registry; + _uiManager = uiManager; + _registry = registry; } return self; } @@ -1693,19 +1693,19 @@ static UIView *_jsResponder; - (id)objectForKey:(id)key { if (![key isKindOfClass:[NSNumber class]]) { - return [super objectForKeyedSubscript:key]; + return [super objectForKey:key]; } NSNumber *index = (NSNumber *)key; - UIView *view = [_uiManager viewForReactTag:index]; + UIView *view = _registry[index]; if (view) { return [RCTUIManager paperViewOrCurrentView:view]; } - view = _registry[index]; + view = [_uiManager viewForReactTag:index]; if (view) { return [RCTUIManager paperViewOrCurrentView:view]; } - return [super objectForKeyedSubscript:key]; + return [super objectForKey:key]; } - (void)removeObjectForKey:(id)key