diff --git a/packages/react-native/ReactCommon/react/bridging/tests/ClassTest.cpp b/packages/react-native/ReactCommon/react/bridging/tests/ClassTest.cpp index f01b9f5c07d..67b63410bca 100644 --- a/packages/react-native/ReactCommon/react/bridging/tests/ClassTest.cpp +++ b/packages/react-native/ReactCommon/react/bridging/tests/ClassTest.cpp @@ -7,33 +7,38 @@ #include "BridgingTest.h" +#include + namespace facebook::react { using namespace std::literals; struct TestClass { - TestClass(std::shared_ptr invoker) : invoker_(invoker) {} + explicit TestClass(std::shared_ptr invoker) + : invoker_(std::move(invoker)) {} - double add(jsi::Runtime&, int a, float b) { + double add(jsi::Runtime& /*unused*/, int a, float b) { return a + b; } - jsi::Object getObject(jsi::Runtime&, jsi::Object obj) { + jsi::Object getObject(jsi::Runtime& /*unused*/, jsi::Object obj) { return obj; } AsyncPromise getPromise(jsi::Runtime& rt, std::string result) { auto promise = AsyncPromise(rt, invoker_); - promise.resolve(result); + promise.resolve(std::move(result)); return promise; } - std::string - callFunc(jsi::Runtime&, SyncCallback func, int num) { + std::string callFunc( + jsi::Runtime& /*unused*/, + SyncCallback func, + int num) { return func(num); } - void callAsync(jsi::Runtime&, AsyncCallback<> callback) { + void callAsync(jsi::Runtime& /*unused*/, const AsyncCallback<>& callback) { callback(); } @@ -69,7 +74,8 @@ TEST_F(BridgingTest, callFromJsTest) { then.callWithThis( rt, promise, - bridging::toJs(rt, [&](std::string res) { result = res; }, invoker)); + bridging::toJs( + rt, [&](std::string res) { result = std::move(res); }, invoker)); flushQueue(); EXPECT_EQ("hi"s, result); diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.cpp index 4ddafa742ad..cdac37316d9 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.cpp @@ -7,6 +7,8 @@ #include "CxxTurboModuleUtils.h" +#include + namespace facebook::react { std::unordered_map< @@ -26,7 +28,8 @@ void registerCxxModuleToGlobalModuleMap( std::string name, std::function( std::shared_ptr jsInvoker)> moduleProviderFunc) { - globalExportedCxxTurboModuleMap()[name] = moduleProviderFunc; + globalExportedCxxTurboModuleMap()[std::move(name)] = + std::move(moduleProviderFunc); } } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.h b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.h index 7a74f04f18e..378cb17cd6c 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.h +++ b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.h @@ -7,11 +7,11 @@ #pragma once -#include -#include - #include #include +#include +#include +#include namespace facebook::react { diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboCxxModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboCxxModule.cpp index 84d57bb1155..cdcb08d5962 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboCxxModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboCxxModule.cpp @@ -20,10 +20,9 @@ namespace facebook::react { namespace { CxxModule::Callback makeTurboCxxModuleCallback( - jsi::Runtime& runtime, std::weak_ptr weakWrapper) { - return [weakWrapper, - wrapperWasCalled = false](std::vector args) mutable { + return [weakWrapper, wrapperWasCalled = false]( + const std::vector& args) mutable { if (wrapperWasCalled) { LOG(FATAL) << "callback arg cannot be called more than once"; } @@ -77,9 +76,9 @@ jsi::Value TurboCxxModule::create( 0, [this]( jsi::Runtime& rt, - const jsi::Value& thisVal, - const jsi::Value* args, - size_t count) { + const jsi::Value& /*thisVal*/, + const jsi::Value* /*args*/, + size_t /*count*/) { jsi::Object result(rt); auto constants = cxxModule_->getConstants(); for (auto& pair : constants) { @@ -97,7 +96,7 @@ jsi::Value TurboCxxModule::create( 0, [this, propNameUtf8]( jsi::Runtime& rt, - const jsi::Value& thisVal, + const jsi::Value& /*thisVal*/, const jsi::Value* args, size_t count) { return invokeMethod(rt, propNameUtf8, args, count); @@ -114,8 +113,8 @@ std::vector TurboCxxModule::getPropertyNames( std::vector result; result.reserve(cxxMethods_.size() + 1); result.push_back(jsi::PropNameID::forUtf8(runtime, "getConstants")); - for (auto it = cxxMethods_.begin(); it != cxxMethods_.end(); it++) { - result.push_back(jsi::PropNameID::forUtf8(runtime, it->name)); + for (auto& cxxMethod : cxxMethods_) { + result.push_back(jsi::PropNameID::forUtf8(runtime, cxxMethod.name)); } return result; } @@ -164,7 +163,7 @@ jsi::Value TurboCxxModule::invokeMethod( args[count - 1].getObject(runtime).getFunction(runtime), runtime, jsInvoker_); - first = makeTurboCxxModuleCallback(runtime, wrapper); + first = makeTurboCxxModuleCallback(wrapper); } else if (method.callbacks == 2) { auto wrapper1 = CallbackWrapper::createWeak( args[count - 2].getObject(runtime).getFunction(runtime), @@ -174,8 +173,8 @@ jsi::Value TurboCxxModule::invokeMethod( args[count - 1].getObject(runtime).getFunction(runtime), runtime, jsInvoker_); - first = makeTurboCxxModuleCallback(runtime, wrapper1); - second = makeTurboCxxModuleCallback(runtime, wrapper2); + first = makeTurboCxxModuleCallback(wrapper1); + second = makeTurboCxxModuleCallback(wrapper2); } auto innerArgs = folly::dynamic::array(); @@ -194,9 +193,9 @@ jsi::Value TurboCxxModule::invokeMethod( auto rejectWrapper = CallbackWrapper::createWeak( promise->reject_.getFunction(rt), rt, jsInvoker_); CxxModule::Callback resolve = - makeTurboCxxModuleCallback(rt, resolveWrapper); + makeTurboCxxModuleCallback(resolveWrapper); CxxModule::Callback reject = - makeTurboCxxModuleCallback(rt, rejectWrapper); + makeTurboCxxModuleCallback(rejectWrapper); auto innerArgs = folly::dynamic::array(); for (size_t i = 0; i < count; i++) { diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp index fe2411974d2..193773b6441 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp @@ -13,7 +13,7 @@ namespace facebook::react { TurboModuleMethodValueKind getTurboModuleMethodValueKind( jsi::Runtime& rt, const jsi::Value* value) { - if (!value || value->isUndefined() || value->isNull()) { + if ((value == nullptr) || value->isUndefined() || value->isNull()) { return VoidKind; } else if (value->isBool()) { return BooleanKind; @@ -41,8 +41,9 @@ TurboModule::TurboModule( void TurboModule::emitDeviceEvent( const std::string& eventName, - ArgFactory argFactory) { - jsInvoker_->invokeAsync([eventName, argFactory](jsi::Runtime& rt) { + ArgFactory&& argFactory) { + jsInvoker_->invokeAsync([eventName, argFactory = std::move(argFactory)]( + jsi::Runtime& rt) { jsi::Value emitter = rt.global().getProperty(rt, "__rctDeviceEventEmitter"); if (!emitter.isUndefined()) { jsi::Object emitterObject = emitter.asObject(rt); diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h index d7bc14e3ef3..9ef16f4cc5c 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h +++ b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h @@ -111,14 +111,14 @@ class JSI_EXPORT TurboModule : public jsi::HostObject { */ void emitDeviceEvent( const std::string& eventName, - ArgFactory argFactory = nullptr); + ArgFactory&& argFactory = nullptr); // Backwards compatibility version void emitDeviceEvent( jsi::Runtime& /*runtime*/, const std::string& eventName, - ArgFactory argFactory = nullptr) { + ArgFactory&& argFactory = nullptr) { emitDeviceEvent(eventName, std::move(argFactory)); } diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp index 3ec219424f3..5ac4fbd2f7e 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp @@ -54,7 +54,7 @@ class BridgelessNativeModuleProxy : public jsi::HostObject { */ std::string moduleName = name.utf8(runtime); if (moduleName == "__esModule") { - return jsi::Value(false); + return {false}; } auto turboModule = turboBinding_.getModule(runtime, moduleName); diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.cpp index c3915063a6a..b881694f96a 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.cpp @@ -35,9 +35,9 @@ jsi::Value createPromiseAsJSIValue( 2, [func = std::move(func)]( jsi::Runtime& rt2, - const jsi::Value& thisVal, + const jsi::Value& /*thisVal*/, const jsi::Value* args, - size_t count) { + size_t /*count*/) { jsi::Function resolve = args[0].getObject(rt2).getFunction(rt2); jsi::Function reject = args[1].getObject(rt2).getFunction(rt2); auto wrapper = std::make_shared( diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.h b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.h index 704116f97eb..7968611db99 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.h +++ b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.h @@ -19,7 +19,7 @@ struct Promise : public LongLivedObject { Promise(jsi::Runtime& rt, jsi::Function resolve, jsi::Function reject); void resolve(const jsi::Value& result); - void reject(const std::string& error); + void reject(const std::string& message); jsi::Function resolve_; jsi::Function reject_; diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaInteropTurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaInteropTurboModule.cpp index 20111b6281b..7c716886d5c 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaInteropTurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaInteropTurboModule.cpp @@ -37,14 +37,15 @@ std::string getType(jsi::Runtime& rt, const jsi::Value& v) { JavaInteropTurboModule::JavaInteropTurboModule( const JavaTurboModule::InitParams& params, - std::vector methodDescriptors) + const std::vector& methodDescriptors) : JavaTurboModule(params), methodDescriptors_(methodDescriptors), methodIDs_(methodDescriptors.size()), constantsCache_(jsi::Value::undefined()) { for (const auto& methodDescriptor : methodDescriptors) { methodMap_[methodDescriptor.methodName] = MethodMetadata{ - static_cast(methodDescriptor.jsArgCount), nullptr}; + .argCount = static_cast(methodDescriptor.jsArgCount), + .invoker = nullptr}; } } @@ -60,7 +61,7 @@ jsi::Value JavaInteropTurboModule::create( static_cast(methodDescriptors_[i].jsArgCount), [this, i]( jsi::Runtime& rt, - const jsi::Value& thisVal, + const jsi::Value& /*thisVal*/, const jsi::Value* args, size_t count) mutable { if (!this->constantsCache_.isUndefined()) { @@ -103,7 +104,7 @@ jsi::Value JavaInteropTurboModule::create( static_cast(methodDescriptors_[i].jsArgCount), [this, i]( jsi::Runtime& rt, - const jsi::Value& thisVal, + const jsi::Value& /*thisVal*/, const jsi::Value* args, size_t count) { return this->invokeJavaMethod( diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaInteropTurboModule.h b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaInteropTurboModule.h index 5a08724aba2..2eb706d7323 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaInteropTurboModule.h +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaInteropTurboModule.h @@ -29,7 +29,7 @@ class JSI_EXPORT JavaInteropTurboModule : public JavaTurboModule { JavaInteropTurboModule( const JavaTurboModule::InitParams& params, - std::vector methodDescriptors); + const std::vector& methodDescriptors); std::vector getPropertyNames( facebook::jsi::Runtime& runtime) override; diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp index 0478f532243..1b1c6f7f7e7 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp @@ -521,7 +521,7 @@ jsi::Value JavaTurboModule::invokeJavaMethod( const char* methodName = methodNameStr.c_str(); const char* moduleName = name_.c_str(); - bool isMethodSync = !(valueKind == VoidKind || valueKind == PromiseKind); + bool isMethodSync = valueKind != VoidKind && valueKind != PromiseKind; if (isMethodSync) { TMPL::syncMethodCallStart(moduleName, methodName); @@ -582,7 +582,7 @@ jsi::Value JavaTurboModule::invokeJavaMethod( } }; - if (!methodID) { + if (methodID == nullptr) { jclass cls = env->GetObjectClass(instance); methodID = env->GetMethodID(cls, methodName, methodSignature.c_str()); @@ -645,7 +645,7 @@ jsi::Value JavaTurboModule::invokeJavaMethod( TMPL::syncMethodCallReturnConversionStart(moduleName, methodName); auto returnValue = jsi::Value::null(); - if (returnObject) { + if (returnObject != nullptr) { auto booleanObj = jni::adopt_local( static_cast(returnObject)); returnValue = jsi::Value(static_cast(booleanObj->value())); @@ -684,7 +684,7 @@ jsi::Value JavaTurboModule::invokeJavaMethod( TMPL::syncMethodCallReturnConversionStart(moduleName, methodName); auto returnValue = jsi::Value::null(); - if (returnObject) { + if (returnObject != nullptr) { if (returnType == "Ljava/lang/Double;") { auto doubleObj = jni::adopt_local( static_cast(returnObject)); @@ -706,8 +706,8 @@ jsi::Value JavaTurboModule::invokeJavaMethod( } else if (returnType == "D" || returnType == "F" || returnType == "I") { jsi::Value returnValue = jsi::Value::undefined(); if (returnType == "D") { - double returnDouble = - (double)env->CallDoubleMethodA(instance, methodID, jargs.data()); + auto returnDouble = static_cast( + env->CallDoubleMethodA(instance, methodID, jargs.data())); checkJNIErrorForMethodCall(); TMPL::syncMethodCallExecutionEnd(moduleName, methodName); @@ -715,8 +715,8 @@ jsi::Value JavaTurboModule::invokeJavaMethod( returnValue = jsi::Value(returnDouble); } else if (returnType == "F") { - float returnFloat = - (float)env->CallFloatMethodA(instance, methodID, jargs.data()); + auto returnFloat = static_cast( + env->CallFloatMethodA(instance, methodID, jargs.data())); checkJNIErrorForMethodCall(); TMPL::syncMethodCallExecutionEnd(moduleName, methodName); @@ -724,8 +724,8 @@ jsi::Value JavaTurboModule::invokeJavaMethod( returnValue = jsi::Value((double)returnFloat); } else if (returnType == "I") { - int returnInt = - (int)env->CallIntMethodA(instance, methodID, jargs.data()); + int returnInt = static_cast( + env->CallIntMethodA(instance, methodID, jargs.data())); checkJNIErrorForMethodCall(); TMPL::syncMethodCallExecutionEnd(moduleName, methodName); @@ -858,7 +858,7 @@ jsi::Value JavaTurboModule::invokeJavaMethod( std::optional> nativeRejectCallback; // The promise constructor runs its arg immediately, so this is safe - jobject javaPromise; + jobject javaPromise = nullptr; jsi::Value jsPromise = Promise.callAsConstructor( runtime, jsi::Function::createFromHostFunction( diff --git a/packages/react-native/ReactCommon/react/nativemodule/dom/NativeDOM.cpp b/packages/react-native/ReactCommon/react/nativemodule/dom/NativeDOM.cpp index fac647c9498..6d6a4ae616b 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/dom/NativeDOM.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/dom/NativeDOM.cpp @@ -299,7 +299,7 @@ NativeDOM::getScrollSize( } std::string NativeDOM::getTagName( - jsi::Runtime& rt, + jsi::Runtime& /*rt*/, std::shared_ptr shadowNode) { return dom::getTagName(*shadowNode); } diff --git a/packages/react-native/ReactCommon/react/nativemodule/idlecallbacks/NativeIdleCallbacks.cpp b/packages/react-native/ReactCommon/react/nativemodule/idlecallbacks/NativeIdleCallbacks.cpp index 33adbb90bb8..d3f29939572 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/idlecallbacks/NativeIdleCallbacks.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/idlecallbacks/NativeIdleCallbacks.cpp @@ -28,7 +28,7 @@ namespace { class IdleTaskRef : public jsi::NativeState { public: - IdleTaskRef(std::shared_ptr task) : task(std::move(task)) {} + explicit IdleTaskRef(std::shared_ptr task) : task(std::move(task)) {} std::shared_ptr task; }; diff --git a/packages/react-native/ReactCommon/react/nativemodule/mutationobserver/NativeMutationObserver.cpp b/packages/react-native/ReactCommon/react/nativemodule/mutationobserver/NativeMutationObserver.cpp index 06e6fe9fa7f..f15b741178a 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/mutationobserver/NativeMutationObserver.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/mutationobserver/NativeMutationObserver.cpp @@ -35,7 +35,7 @@ NativeMutationObserver::NativeMutationObserver( void NativeMutationObserver::observe( jsi::Runtime& runtime, - NativeMutationObserverObserveOptions options) { + const NativeMutationObserverObserveOptions& options) { auto mutationObserverId = options.mutationObserverId; auto subtree = options.subtree; auto shadowNode = options.targetShadowNode; @@ -46,7 +46,7 @@ void NativeMutationObserver::observe( } void NativeMutationObserver::unobserveAll( - jsi::Runtime& runtime, + jsi::Runtime& /*runtime*/, MutationObserverId mutationObserverId) { mutationObserverManager_.unobserveAll(mutationObserverId); } diff --git a/packages/react-native/ReactCommon/react/nativemodule/mutationobserver/NativeMutationObserver.h b/packages/react-native/ReactCommon/react/nativemodule/mutationobserver/NativeMutationObserver.h index 9a8fa03d245..8601276d383 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/mutationobserver/NativeMutationObserver.h +++ b/packages/react-native/ReactCommon/react/nativemodule/mutationobserver/NativeMutationObserver.h @@ -51,7 +51,7 @@ class NativeMutationObserver void observe( jsi::Runtime& runtime, - NativeMutationObserverObserveOptions options); + const NativeMutationObserverObserveOptions& options); void unobserveAll( jsi::Runtime& runtime, diff --git a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/android/ReactCommon/SampleTurboModuleSpec.cpp b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/android/ReactCommon/SampleTurboModuleSpec.cpp index 02787bc1e5e..f004350f438 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/samples/platform/android/ReactCommon/SampleTurboModuleSpec.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/samples/platform/android/ReactCommon/SampleTurboModuleSpec.cpp @@ -332,45 +332,67 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI( const JavaTurboModule::InitParams& params) : JavaTurboModule(params) { methodMap_["getConstants"] = MethodMetadata{ - 0, __hostFunction_NativeSampleTurboModuleSpecJSI_getConstants}; - methodMap_["voidFunc"] = - MethodMetadata{0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc}; - methodMap_["getBool"] = - MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getBool}; - methodMap_["getEnum"] = - MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getEnum}; + .argCount = 0, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getConstants}; + methodMap_["voidFunc"] = MethodMetadata{ + .argCount = 0, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc}; + methodMap_["getBool"] = MethodMetadata{ + .argCount = 1, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getBool}; + methodMap_["getEnum"] = MethodMetadata{ + .argCount = 1, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getEnum}; methodMap_["getNumber"] = MethodMetadata{ - 1, __hostFunction_NativeSampleTurboModuleSpecJSI_getNumber}; + .argCount = 1, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getNumber}; methodMap_["getString"] = MethodMetadata{ - 1, __hostFunction_NativeSampleTurboModuleSpecJSI_getString}; - methodMap_["getArray"] = - MethodMetadata{1, __hostFunction_NativeSampleTurboModuleSpecJSI_getArray}; + .argCount = 1, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getString}; + methodMap_["getArray"] = MethodMetadata{ + .argCount = 1, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getArray}; methodMap_["getObject"] = MethodMetadata{ - 1, __hostFunction_NativeSampleTurboModuleSpecJSI_getObject}; + .argCount = 1, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getObject}; methodMap_["getUnsafeObject"] = MethodMetadata{ - 1, __hostFunction_NativeSampleTurboModuleSpecJSI_getUnsafeObject}; + .argCount = 1, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getUnsafeObject}; methodMap_["getRootTag"] = MethodMetadata{ - 1, __hostFunction_NativeSampleTurboModuleSpecJSI_getRootTag}; - methodMap_["getValue"] = - MethodMetadata{3, __hostFunction_NativeSampleTurboModuleSpecJSI_getValue}; + .argCount = 1, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getRootTag}; + methodMap_["getValue"] = MethodMetadata{ + .argCount = 3, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getValue}; methodMap_["getValueWithCallback"] = MethodMetadata{ - 1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithCallback}; + .argCount = 1, + .invoker = + __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithCallback}; methodMap_["getValueWithPromise"] = MethodMetadata{ - 1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise}; + .argCount = 1, + .invoker = + __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise}; methodMap_["voidFuncThrows"] = MethodMetadata{ - 0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFuncThrows}; + .argCount = 0, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_voidFuncThrows}; methodMap_["getObjectThrows"] = MethodMetadata{ - 1, __hostFunction_NativeSampleTurboModuleSpecJSI_getObjectThrows}; + .argCount = 1, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getObjectThrows}; methodMap_["promiseThrows"] = MethodMetadata{ - 0, __hostFunction_NativeSampleTurboModuleSpecJSI_promiseThrows}; + .argCount = 0, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_promiseThrows}; methodMap_["voidFuncAssert"] = MethodMetadata{ - 0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFuncAssert}; + .argCount = 0, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_voidFuncAssert}; methodMap_["getObjectAssert"] = MethodMetadata{ - 1, __hostFunction_NativeSampleTurboModuleSpecJSI_getObjectAssert}; + .argCount = 1, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getObjectAssert}; methodMap_["promiseAssert"] = MethodMetadata{ - 0, __hostFunction_NativeSampleTurboModuleSpecJSI_promiseAssert}; + .argCount = 0, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_promiseAssert}; methodMap_["getImageUrl"] = MethodMetadata{ - 0, __hostFunction_NativeSampleTurboModuleSpecJSI_getImageUrl}; + .argCount = 0, + .invoker = __hostFunction_NativeSampleTurboModuleSpecJSI_getImageUrl}; eventEmitterMap_["onPress"] = std::make_shared>(); eventEmitterMap_["onClick"] = diff --git a/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.cpp b/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.cpp index 9766b8d05c1..6259ff0bbbe 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.cpp @@ -136,7 +136,7 @@ HighResTimeStamp NativePerformance::now(jsi::Runtime& /*rt*/) { void NativePerformance::reportMark( jsi::Runtime& rt, - std::string name, + const std::string& name, HighResTimeStamp startTime, jsi::Value entry) { PerformanceEntryReporter::getInstance()->reportMark( @@ -145,7 +145,7 @@ void NativePerformance::reportMark( void NativePerformance::reportMeasure( jsi::Runtime& rt, - std::string name, + const std::string& name, HighResTimeStamp startTime, HighResDuration duration, jsi::Value entry) { @@ -154,8 +154,8 @@ void NativePerformance::reportMeasure( } std::optional NativePerformance::getMarkTime( - jsi::Runtime& rt, - std::string name) { + jsi::Runtime& /*rt*/, + const std::string& name) { auto markTime = PerformanceEntryReporter::getInstance()->getMarkTime(name); return markTime ? std::optional{(*markTime).toDOMHighResTimeStamp()} : std::nullopt; @@ -200,7 +200,7 @@ std::vector NativePerformance::getEntries( std::vector NativePerformance::getEntriesByName( jsi::Runtime& /*rt*/, - std::string entryName, + const std::string& entryName, std::optional entryType) { std::vector entries; @@ -253,7 +253,7 @@ std::unordered_map NativePerformance::getSimpleMemoryInfo( } std::unordered_map -NativePerformance::getReactNativeStartupTiming(jsi::Runtime& rt) { +NativePerformance::getReactNativeStartupTiming(jsi::Runtime& /*rt*/) { std::unordered_map result; ReactMarker::StartupLogger& startupLogger = diff --git a/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.h b/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.h index 27971617d11..8dcf591f855 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.h +++ b/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.h @@ -92,18 +92,18 @@ class NativePerformance : public NativePerformanceCxxSpec { void reportMark( jsi::Runtime& rt, - std::string name, + const std::string& name, HighResTimeStamp time, jsi::Value entry); void reportMeasure( jsi::Runtime& rt, - std::string name, + const std::string& name, HighResTimeStamp startTime, HighResDuration duration, jsi::Value entry); - std::optional getMarkTime(jsi::Runtime& rt, std::string name); + std::optional getMarkTime(jsi::Runtime& rt, const std::string& name); // https://w3c.github.io/user-timing/#clearmarks-method void clearMarks( @@ -128,7 +128,7 @@ class NativePerformance : public NativePerformanceCxxSpec { // https://www.w3.org/TR/performance-timeline/#getentriesbyname-method std::vector getEntriesByName( jsi::Runtime& rt, - std::string entryName, + const std::string& entryName, std::optional entryType = std::nullopt); #pragma mark - Performance Observer (https://w3c.github.io/performance-timeline/#the-performanceobserver-interface) diff --git a/packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryKeyedBuffer.cpp b/packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryKeyedBuffer.cpp index 97914ad54d4..b21301d87ad 100644 --- a/packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryKeyedBuffer.cpp +++ b/packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryKeyedBuffer.cpp @@ -33,9 +33,7 @@ void PerformanceEntryKeyedBuffer::getEntries( void PerformanceEntryKeyedBuffer::getEntries( std::vector& target, const std::string& name) const { - std::string nameStr{name}; - - if (auto node = entryMap_.find(nameStr); node != entryMap_.end()) { + if (auto node = entryMap_.find(name); node != entryMap_.end()) { target.insert(target.end(), node->second.begin(), node->second.end()); } }