Skip to content

Commit 12e5df8

Browse files
rozelefacebook-github-bot
authored andcommitted
Convert folly::dynamic event dispatch to r-value (#50133)
Summary: Pull Request resolved: #50133 Allow move semantics for folly::dynamic event dispatching to avoid copying the folly::dynamic when dispatched. ## Changelog [General][Breaking] - Dispatch folly::dynamic events with r-value instead of l-value Reviewed By: NickGerleman Differential Revision: D71423497 fbshipit-source-id: 5435772e14b025aab97d34df9983b91fd7285fd0
1 parent 146d809 commit 12e5df8

10 files changed

+14
-67
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,11 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
212212
if (!_adapter) {
213213
_adapter = [[RCTLegacyViewManagerInteropCoordinatorAdapter alloc] initWithCoordinator:[self _coordinator]
214214
reactTag:self.tag];
215-
_adapter.eventInterceptor = ^(std::string eventName, folly::dynamic event) {
215+
_adapter.eventInterceptor = ^(std::string eventName, folly::dynamic &&event) {
216216
if (weakSelf) {
217217
__typeof(self) strongSelf = weakSelf;
218-
const auto &eventEmitter =
219-
static_cast<const LegacyViewManagerInteropViewEventEmitter &>(*strongSelf->_eventEmitter);
220-
eventEmitter.dispatchEvent(eventName, event);
218+
const auto &eventEmitter = static_cast<const ViewEventEmitter &>(*strongSelf->_eventEmitter);
219+
eventEmitter.dispatchEvent(eventName, std::move(event));
221220
}
222221
};
223222
// Set props immediately. This is required to set the initial state of the view.

packages/react-native/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropCoordinatorAdapter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
1616

1717
@property (strong, nonatomic) UIView *paperView;
1818

19-
@property (nonatomic, copy, nullable) void (^eventInterceptor)(std::string eventName, folly::dynamic event);
19+
@property (nonatomic, copy, nullable) void (^eventInterceptor)(std::string eventName, folly::dynamic &&event);
2020

2121
- (void)setProps:(const folly::dynamic &)props;
2222

packages/react-native/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropCoordinatorAdapter.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ - (UIView *)paperView
3636
_paperView = [_coordinator createPaperViewWithTag:_tag];
3737
__weak __typeof(self) weakSelf = self;
3838
[_coordinator addObserveForTag:_tag
39-
usingBlock:^(std::string eventName, folly::dynamic event) {
39+
usingBlock:^(std::string eventName, folly::dynamic &&event) {
4040
if (weakSelf.eventInterceptor) {
41-
weakSelf.eventInterceptor(eventName, event);
41+
weakSelf.eventInterceptor(eventName, std::move(event));
4242
}
4343
}];
4444
}

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropShadowNode.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#pragma once
99

1010
#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropState.h>
11-
#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewEventEmitter.h>
1211
#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.h>
1312
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
1413

@@ -19,7 +18,7 @@ extern const char LegacyViewManagerInteropComponentName[];
1918
using LegacyViewManagerInteropShadowNode = ConcreteViewShadowNode<
2019
LegacyViewManagerInteropComponentName,
2120
LegacyViewManagerInteropViewProps,
22-
LegacyViewManagerInteropViewEventEmitter,
21+
ViewEventEmitter,
2322
LegacyViewManagerInteropState>;
2423

2524
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewEventEmitter.cpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewEventEmitter.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
1616
@class RCTBridge;
1717
@class RCTBridgeProxy;
1818

19-
typedef void (^InterceptorBlock)(std::string eventName, folly::dynamic event);
19+
typedef void (^InterceptorBlock)(std::string eventName, folly::dynamic &&event);
2020

2121
@interface RCTLegacyViewManagerInteropCoordinator : NSObject
2222

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/UnstableLegacyViewManagerAutomaticShadowNode.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#pragma once
99

10-
#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewEventEmitter.h>
1110
#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.h>
1211
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
1312

packages/react-native/ReactCommon/react/renderer/core/EventEmitter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ EventEmitter::EventEmitter(
5757

5858
void EventEmitter::dispatchEvent(
5959
std::string type,
60-
const folly::dynamic& payload,
60+
folly::dynamic&& payload,
6161
RawEvent::Category category) const {
6262
dispatchEvent(
6363
std::move(type),
64-
std::make_shared<DynamicEventPayload>(folly::dynamic(payload)),
64+
std::make_shared<DynamicEventPayload>(std::move(payload)),
6565
category);
6666
}
6767

6868
void EventEmitter::dispatchUniqueEvent(
6969
std::string type,
70-
const folly::dynamic& payload) const {
70+
folly::dynamic&& payload) const {
7171
dispatchUniqueEvent(
7272
std::move(type),
73-
std::make_shared<DynamicEventPayload>(folly::dynamic(payload)));
73+
std::make_shared<DynamicEventPayload>(std::move(payload)));
7474
}
7575

7676
void EventEmitter::dispatchEvent(

packages/react-native/ReactCommon/react/renderer/core/EventEmitter.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,15 @@ class EventEmitter {
8686

8787
void dispatchEvent(
8888
std::string type,
89-
const folly::dynamic& payload,
89+
folly::dynamic&& payload,
9090
RawEvent::Category category = RawEvent::Category::Unspecified) const;
9191

9292
void dispatchEvent(
9393
std::string type,
9494
SharedEventPayload payload,
9595
RawEvent::Category category = RawEvent::Category::Unspecified) const;
9696

97-
void dispatchUniqueEvent(std::string type, const folly::dynamic& payload)
98-
const;
97+
void dispatchUniqueEvent(std::string type, folly::dynamic&& payload) const;
9998

10099
void dispatchUniqueEvent(
101100
std::string type,

0 commit comments

Comments
 (0)