Skip to content

Commit

Permalink
Remove Props copy constructor and assignment operators (#40936)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #40936

Found a couple of places where we were accidentally copying Props structs. These can be big, so we should avoid doing so.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D50263678

fbshipit-source-id: f60a0370df9b7f3f146988148d5192d3cc32fb4e
  • Loading branch information
javache authored and facebook-github-bot committed Oct 16, 2023
1 parent 171a479 commit bbc517c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ void YogaLayoutableShadowNode::updateYogaChildren() {
void YogaLayoutableShadowNode::updateYogaProps() {
ensureUnsealed();

auto props = static_cast<const YogaStylableProps&>(*props_);
auto& props = static_cast<const YogaStylableProps&>(*props_);
auto styleResult = applyAliasedProps(props.yogaStyle, props);

// Resetting `dirty` flag only if `yogaStyle` portion of `Props` was changed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class ConcreteShadowNode : public BaseShadowNodeT {
const Props::Shared& baseProps = nullptr) {
return std::make_shared<PropsT>(
context,
baseProps ? static_cast<const PropsT&>(*baseProps) : PropsT(),
baseProps ? static_cast<const PropsT&>(*baseProps)
: *defaultSharedProps(),
rawProps);
}

Expand Down
3 changes: 3 additions & 0 deletions packages/react-native/ReactCommon/react/renderer/core/Props.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class Props : public virtual Sealable, public virtual DebugStringConvertible {
const RawProps& rawProps);
virtual ~Props() = default;

Props(const Props& other) = delete;
Props& operator=(const Props& other) = delete;

/**
* Set a prop value via iteration (see enableIterator above).
* If setProp is defined for a particular props struct, it /must/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ static bool isViewListeningToEvents(
const ShadowNode& shadowNode,
std::initializer_list<ViewEvents::Offset> eventTypes) {
if (shadowNode.getTraits().check(ShadowNodeTraits::Trait::ViewKind)) {
auto props = shadowNode.getProps();
auto viewProps = static_cast<const ViewProps&>(*props);

auto& viewProps = static_cast<const ViewProps&>(*shadowNode.getProps());
for (const ViewEvents::Offset eventType : eventTypes) {
if (viewProps.events[eventType]) {
return true;
Expand Down

0 comments on commit bbc517c

Please sign in to comment.