From 0892e986f44bdae0cee97ed7e3e6e0ce93593800 Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Thu, 21 Sep 2023 16:01:32 -0700 Subject: [PATCH] lift isSyncModule_ check outside of isMethodSync Summary: Changelog: [Internal] some cleanup! Differential Revision: D49521863 fbshipit-source-id: 9a31b2ae48069f3b8722b99889db0b8695b4f40d --- .../platform/ios/ReactCommon/RCTTurboModule.mm | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm index 5944ab1be7adff..9fb6ec560fc7bb 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm @@ -680,7 +680,7 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s bool ObjCTurboModule::isMethodSync(TurboModuleMethodValueKind returnType) { - return isSyncModule_ || !(returnType == VoidKind || returnType == PromiseKind); + return !(returnType == VoidKind || returnType == PromiseKind); } ObjCTurboModule::ObjCTurboModule(const InitParams ¶ms) @@ -703,7 +703,9 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s const char *moduleName = name_.c_str(); const char *methodName = methodNameStr.c_str(); - if (isMethodSync(returnType)) { + bool isSyncInvocation = isSyncModule_ || isMethodSync(returnType); + + if (isSyncInvocation) { TurboModulePerfLogger::syncMethodCallStart(moduleName, methodName); } else { TurboModulePerfLogger::asyncMethodCallStart(moduleName, methodName); @@ -711,7 +713,7 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s NSMutableArray *retainedObjectsForInvocation = [NSMutableArray arrayWithCapacity:count + 2]; NSInvocation *inv = createMethodInvocation( - runtime, isMethodSync(returnType), methodName, selector, args, count, retainedObjectsForInvocation); + runtime, isSyncInvocation, methodName, selector, args, count, retainedObjectsForInvocation); jsi::Value returnValue = jsi::Value::undefined(); @@ -726,24 +728,24 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s [retainedObjectsForInvocation addObject:resolveCopy]; [retainedObjectsForInvocation addObject:rejectCopy]; // The return type becomes void in the ObjC side. - performMethodInvocation(runtime, isMethodSync(VoidKind), methodName, inv, retainedObjectsForInvocation); + performMethodInvocation(runtime, isSyncInvocation, methodName, inv, retainedObjectsForInvocation); }); } else { id result = - performMethodInvocation(runtime, isMethodSync(returnType), methodName, inv, retainedObjectsForInvocation); + performMethodInvocation(runtime, isSyncInvocation, methodName, inv, retainedObjectsForInvocation); - if (isMethodSync(returnType)) { + if (isSyncInvocation) { TurboModulePerfLogger::syncMethodCallReturnConversionStart(moduleName, methodName); } returnValue = convertReturnIdToJSIValue(runtime, methodName, returnType, result); - if (isMethodSync(returnType)) { + if (isSyncInvocation) { TurboModulePerfLogger::syncMethodCallReturnConversionEnd(moduleName, methodName); } } - if (isMethodSync(returnType)) { + if (isSyncInvocation) { TurboModulePerfLogger::syncMethodCallEnd(moduleName, methodName); } else { TurboModulePerfLogger::asyncMethodCallEnd(moduleName, methodName);