Skip to content

Commit

Permalink
perf: avoid unnecessary shared_ptr copies in Fabric components (#2164)
Browse files Browse the repository at this point in the history
Ports the upstream best-practice around props handling of shared_ptr in facebook/react-native@a855013
  • Loading branch information
javache authored Oct 25, 2023
1 parent a5dae2f commit 5208a2f
Show file tree
Hide file tree
Showing 21 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGClipPath.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGClipPathProps>(props);
const auto &newProps = static_cast<const RNSVGClipPathProps &>(*props);
setCommonNodeProps(newProps, self);
_props = std::static_pointer_cast<RNSVGClipPathProps const>(props);
}
Expand Down
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGForeignObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGForeignObjectProps>(props);
const auto &newProps = static_cast<const RNSVGForeignObjectProps &>(*props);

self.x = RCTNSStringFromStringNilIfEmpty(newProps.x)
? [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)]
Expand Down
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGGroup.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGGroupProps>(props);
const auto &newProps = static_cast<const RNSVGGroupProps &>(*props);

setCommonGroupProps(newProps, self);
_props = std::static_pointer_cast<RNSVGGroupProps const>(props);
Expand Down
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGImageProps>(props);
const auto &newProps = static_cast<const RNSVGImageProps &>(*props);

self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)];
self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)];
Expand Down
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGLinearGradient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGLinearGradientProps>(props);
const auto &newProps = static_cast<const RNSVGLinearGradientProps &>(*props);

self.x1 = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x1)];
self.y1 = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y1)];
Expand Down
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGMarker.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGMarkerProps>(props);
const auto &newProps = static_cast<const RNSVGMarkerProps &>(*props);

self.refX = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.refX)];
self.refY = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.refY)];
Expand Down
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGMask.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGMaskProps>(props);
const auto &newProps = static_cast<const RNSVGMaskProps &>(*props);

self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)];
self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)];
Expand Down
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGPath.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGPathProps>(props);
const auto &newProps = static_cast<const RNSVGPathProps &>(*props);
self.d = [[RNSVGPathParser alloc] initWithPathString:RCTNSStringFromString(newProps.d)];

setCommonRenderableProps(newProps, self);
Expand Down
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGPattern.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGPatternProps>(props);
const auto &newProps = static_cast<const RNSVGPatternProps &>(*props);

self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)];
self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)];
Expand Down
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGRadialGradient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGRadialGradientProps>(props);
const auto &newProps = static_cast<const RNSVGRadialGradientProps &>(*props);

self.fx = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.fx)];
self.fy = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.fy)];
Expand Down
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGSvgView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGSvgViewProps>(props);
const auto &newProps = static_cast<const RNSVGSvgViewProps &>(*props);

self.minX = newProps.minX;
self.minY = newProps.minY;
Expand Down
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGSymbol.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGSymbolProps>(props);
const auto &newProps = static_cast<const RNSVGSymbolProps &>(*props);

self.minX = newProps.minX;
self.minY = newProps.minY;
Expand Down
2 changes: 1 addition & 1 deletion apple/Elements/RNSVGUse.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGUseProps>(props);
const auto &newProps = static_cast<const RNSVGUseProps &>(*props);

self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)];
self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)];
Expand Down
2 changes: 1 addition & 1 deletion apple/Shapes/RNSVGCircle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGCircleProps>(props);
const auto &newProps = static_cast<const RNSVGCircleProps &>(*props);

self.cx = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.cx)];
self.cy = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.cy)];
Expand Down
2 changes: 1 addition & 1 deletion apple/Shapes/RNSVGEllipse.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGEllipseProps>(props);
const auto &newProps = static_cast<const RNSVGEllipseProps &>(*props);

self.cx = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.cx)];
self.cy = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.cy)];
Expand Down
2 changes: 1 addition & 1 deletion apple/Shapes/RNSVGLine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGLineProps>(props);
const auto &newProps = static_cast<const RNSVGLineProps &>(*props);

self.x1 = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x1)];
self.y1 = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y1)];
Expand Down
2 changes: 1 addition & 1 deletion apple/Shapes/RNSVGRect.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGRectProps>(props);
const auto &newProps = static_cast<const RNSVGRectProps &>(*props);

self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)];
self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)];
Expand Down
2 changes: 1 addition & 1 deletion apple/Text/RNSVGTSpan.mm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGTSpanProps>(props);
const auto &newProps = static_cast<const RNSVGTSpanProps &>(*props);

self.content = RCTNSStringFromStringNilIfEmpty(newProps.content);

Expand Down
2 changes: 1 addition & 1 deletion apple/Text/RNSVGText.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGTextProps>(props);
const auto &newProps = static_cast<const RNSVGTextProps &>(*props);

setCommonTextProps(newProps, self);
_props = std::static_pointer_cast<RNSVGTextProps const>(props);
Expand Down
2 changes: 1 addition & 1 deletion apple/Text/RNSVGTextPath.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &newProps = *std::static_pointer_cast<const RNSVGTextPathProps>(props);
const auto &newProps = static_cast<const RNSVGTextPathProps &>(*props);

self.href = RCTNSStringFromStringNilIfEmpty(newProps.href);
self.side = RCTNSStringFromStringNilIfEmpty(newProps.side);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ class RNSVGImageComponentDescriptor final
void adopt(ShadowNode::Unshared const &shadowNode) const override {
ConcreteComponentDescriptor::adopt(shadowNode);

auto imageShadowNode =
std::static_pointer_cast<RNSVGImageShadowNode>(shadowNode);
auto &imageShadowNode = static_cast<RNSVGImageShadowNode &>(*shadowNode);

// `RNSVGImageShadowNode` uses `ImageManager` to initiate image loading and
// communicate the loading state and results to mounting layer.
imageShadowNode->setImageManager(imageManager_);
imageShadowNode.setImageManager(imageManager_);
}

private:
Expand Down

0 comments on commit 5208a2f

Please sign in to comment.