Skip to content

Commit 45ff33f

Browse files
rozelefacebook-github-bot
authored andcommitted
Convert folly::dynamic event dispatch to r-value
Summary: Allow move semantics for folly::dynamic event dispatching to avoid copying the folly::dynamic when dispatched. ## Changelog [Breaking][Changed] - Dispatch folly::dynamic events with r-value instead of l-value Differential Revision: D71423497
1 parent 81e47af commit 45ff33f

File tree

7 files changed

+8
-61
lines changed

7 files changed

+8
-61
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
215215
_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);
218+
const auto &eventEmitter = static_cast<const ViewEventEmitter &>(*strongSelf->_eventEmitter);
220219
eventEmitter.dispatchEvent(eventName, event);
221220
}
222221
};

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/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)