perf: Move func into CallInvoker::invokeAsync (#54141)

Summary:
Instead of copying the `std::function` into `invokeAsync`, we now move it.

## Changelog:

[GENERAL] [CHANGED] - Move `std::function` into `CallInvoker::invokeAsync` instead of copying it

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: https://github.com/facebook/react-native/pull/54141

Test Plan: Build, run. A lot of code still uses the old `invokeAsync` function.

Reviewed By: christophpurrer

Differential Revision: D84563949

Pulled By: javache

fbshipit-source-id: 283be3d12f1ac1c7f3da528c6b50b36cc81cd82a
This commit is contained in:
Marc Rousavy
2025-10-13 23:49:08 -07:00
committed by meta-codesync[bot]
parent 6d7a93f2b1
commit 5ffff0153c
@@ -38,11 +38,11 @@ class CallInvoker {
// Backward compatibility only, prefer the CallFunc methods instead
virtual void invokeAsync(std::function<void()>&& func) noexcept {
invokeAsync([func](jsi::Runtime&) { func(); });
invokeAsync([func = std::move(func)](jsi::Runtime&) { func(); });
}
virtual void invokeSync(std::function<void()>&& func) {
invokeSync([func](jsi::Runtime&) { func(); });
invokeSync([func = std::move(func)](jsi::Runtime&) { func(); });
}
virtual ~CallInvoker() = default;