From be293364c59b5a620645314ff9f022735611e2c6 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Tue, 24 Oct 2023 10:32:19 +0100 Subject: [PATCH] perf: avoid unnecessary shared_ptr copies --- apple/Elements/RNSVGClipPath.mm | 2 +- apple/Elements/RNSVGForeignObject.mm | 2 +- apple/Elements/RNSVGGroup.mm | 2 +- apple/Elements/RNSVGImage.mm | 2 +- apple/Elements/RNSVGLinearGradient.mm | 2 +- apple/Elements/RNSVGMarker.mm | 2 +- apple/Elements/RNSVGMask.mm | 2 +- apple/Elements/RNSVGPath.mm | 2 +- apple/Elements/RNSVGPattern.mm | 2 +- apple/Elements/RNSVGRadialGradient.mm | 2 +- apple/Elements/RNSVGSvgView.mm | 2 +- apple/Elements/RNSVGSymbol.mm | 2 +- apple/Elements/RNSVGUse.mm | 2 +- apple/Shapes/RNSVGCircle.mm | 2 +- apple/Shapes/RNSVGEllipse.mm | 2 +- apple/Shapes/RNSVGLine.mm | 2 +- apple/Shapes/RNSVGRect.mm | 2 +- apple/Text/RNSVGTSpan.mm | 2 +- apple/Text/RNSVGText.mm | 2 +- apple/Text/RNSVGTextPath.mm | 2 +- .../components/rnsvg/RNSVGImageComponentDescriptor.h | 5 ++--- 21 files changed, 22 insertions(+), 23 deletions(-) diff --git a/apple/Elements/RNSVGClipPath.mm b/apple/Elements/RNSVGClipPath.mm index 8b2dcf8be..e1593b700 100644 --- a/apple/Elements/RNSVGClipPath.mm +++ b/apple/Elements/RNSVGClipPath.mm @@ -39,7 +39,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); setCommonNodeProps(newProps, self); _props = std::static_pointer_cast(props); } diff --git a/apple/Elements/RNSVGForeignObject.mm b/apple/Elements/RNSVGForeignObject.mm index 8fb44c6b7..45cb7bee2 100644 --- a/apple/Elements/RNSVGForeignObject.mm +++ b/apple/Elements/RNSVGForeignObject.mm @@ -41,7 +41,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.x = RCTNSStringFromStringNilIfEmpty(newProps.x) ? [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)] diff --git a/apple/Elements/RNSVGGroup.mm b/apple/Elements/RNSVGGroup.mm index 17138e6dd..9855d26e0 100644 --- a/apple/Elements/RNSVGGroup.mm +++ b/apple/Elements/RNSVGGroup.mm @@ -43,7 +43,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); setCommonGroupProps(newProps, self); _props = std::static_pointer_cast(props); diff --git a/apple/Elements/RNSVGImage.mm b/apple/Elements/RNSVGImage.mm index 1b7116584..6e5c27f70 100644 --- a/apple/Elements/RNSVGImage.mm +++ b/apple/Elements/RNSVGImage.mm @@ -72,7 +72,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)]; self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)]; diff --git a/apple/Elements/RNSVGLinearGradient.mm b/apple/Elements/RNSVGLinearGradient.mm index ea891a4d4..6a20af885 100644 --- a/apple/Elements/RNSVGLinearGradient.mm +++ b/apple/Elements/RNSVGLinearGradient.mm @@ -40,7 +40,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.x1 = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x1)]; self.y1 = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y1)]; diff --git a/apple/Elements/RNSVGMarker.mm b/apple/Elements/RNSVGMarker.mm index b899554ac..88e4daf99 100644 --- a/apple/Elements/RNSVGMarker.mm +++ b/apple/Elements/RNSVGMarker.mm @@ -42,7 +42,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.refX = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.refX)]; self.refY = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.refY)]; diff --git a/apple/Elements/RNSVGMask.mm b/apple/Elements/RNSVGMask.mm index f80a8e9cb..c482e8772 100644 --- a/apple/Elements/RNSVGMask.mm +++ b/apple/Elements/RNSVGMask.mm @@ -41,7 +41,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)]; self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)]; diff --git a/apple/Elements/RNSVGPath.mm b/apple/Elements/RNSVGPath.mm index 1bc92f17d..2db13c028 100644 --- a/apple/Elements/RNSVGPath.mm +++ b/apple/Elements/RNSVGPath.mm @@ -41,7 +41,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.d = [[RNSVGPathParser alloc] initWithPathString:RCTNSStringFromString(newProps.d)]; setCommonRenderableProps(newProps, self); diff --git a/apple/Elements/RNSVGPattern.mm b/apple/Elements/RNSVGPattern.mm index 0c6ff0aca..400dbed97 100644 --- a/apple/Elements/RNSVGPattern.mm +++ b/apple/Elements/RNSVGPattern.mm @@ -41,7 +41,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)]; self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)]; diff --git a/apple/Elements/RNSVGRadialGradient.mm b/apple/Elements/RNSVGRadialGradient.mm index d7ed4afb8..6be35092b 100644 --- a/apple/Elements/RNSVGRadialGradient.mm +++ b/apple/Elements/RNSVGRadialGradient.mm @@ -38,7 +38,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.fx = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.fx)]; self.fy = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.fy)]; diff --git a/apple/Elements/RNSVGSvgView.mm b/apple/Elements/RNSVGSvgView.mm index 4c1cc6a28..e7319b35e 100644 --- a/apple/Elements/RNSVGSvgView.mm +++ b/apple/Elements/RNSVGSvgView.mm @@ -64,7 +64,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.minX = newProps.minX; self.minY = newProps.minY; diff --git a/apple/Elements/RNSVGSymbol.mm b/apple/Elements/RNSVGSymbol.mm index a81bc3945..865040775 100644 --- a/apple/Elements/RNSVGSymbol.mm +++ b/apple/Elements/RNSVGSymbol.mm @@ -39,7 +39,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.minX = newProps.minX; self.minY = newProps.minY; diff --git a/apple/Elements/RNSVGUse.mm b/apple/Elements/RNSVGUse.mm index d0485b7bb..3350713fe 100644 --- a/apple/Elements/RNSVGUse.mm +++ b/apple/Elements/RNSVGUse.mm @@ -40,7 +40,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)]; self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)]; diff --git a/apple/Shapes/RNSVGCircle.mm b/apple/Shapes/RNSVGCircle.mm index f92960beb..569e0028a 100644 --- a/apple/Shapes/RNSVGCircle.mm +++ b/apple/Shapes/RNSVGCircle.mm @@ -40,7 +40,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.cx = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.cx)]; self.cy = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.cy)]; diff --git a/apple/Shapes/RNSVGEllipse.mm b/apple/Shapes/RNSVGEllipse.mm index 05ebf3d62..f212445ea 100644 --- a/apple/Shapes/RNSVGEllipse.mm +++ b/apple/Shapes/RNSVGEllipse.mm @@ -40,7 +40,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.cx = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.cx)]; self.cy = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.cy)]; diff --git a/apple/Shapes/RNSVGLine.mm b/apple/Shapes/RNSVGLine.mm index 789cdc523..868b948e9 100644 --- a/apple/Shapes/RNSVGLine.mm +++ b/apple/Shapes/RNSVGLine.mm @@ -40,7 +40,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.x1 = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x1)]; self.y1 = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y1)]; diff --git a/apple/Shapes/RNSVGRect.mm b/apple/Shapes/RNSVGRect.mm index bfc6833d5..071900203 100644 --- a/apple/Shapes/RNSVGRect.mm +++ b/apple/Shapes/RNSVGRect.mm @@ -40,7 +40,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.x = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.x)]; self.y = [RNSVGLength lengthWithString:RCTNSStringFromString(newProps.y)]; diff --git a/apple/Text/RNSVGTSpan.mm b/apple/Text/RNSVGTSpan.mm index a2fee5f95..284c22b9d 100644 --- a/apple/Text/RNSVGTSpan.mm +++ b/apple/Text/RNSVGTSpan.mm @@ -58,7 +58,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.content = RCTNSStringFromStringNilIfEmpty(newProps.content); diff --git a/apple/Text/RNSVGText.mm b/apple/Text/RNSVGText.mm index 311914144..c3d11bb13 100644 --- a/apple/Text/RNSVGText.mm +++ b/apple/Text/RNSVGText.mm @@ -49,7 +49,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); setCommonTextProps(newProps, self); _props = std::static_pointer_cast(props); diff --git a/apple/Text/RNSVGTextPath.mm b/apple/Text/RNSVGTextPath.mm index a7cc4e621..b5403f6af 100644 --- a/apple/Text/RNSVGTextPath.mm +++ b/apple/Text/RNSVGTextPath.mm @@ -39,7 +39,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps { - const auto &newProps = *std::static_pointer_cast(props); + const auto &newProps = static_cast(*props); self.href = RCTNSStringFromStringNilIfEmpty(newProps.href); self.side = RCTNSStringFromStringNilIfEmpty(newProps.side); diff --git a/common/cpp/react/renderer/components/rnsvg/RNSVGImageComponentDescriptor.h b/common/cpp/react/renderer/components/rnsvg/RNSVGImageComponentDescriptor.h index 87a29e392..e00d3525d 100644 --- a/common/cpp/react/renderer/components/rnsvg/RNSVGImageComponentDescriptor.h +++ b/common/cpp/react/renderer/components/rnsvg/RNSVGImageComponentDescriptor.h @@ -29,12 +29,11 @@ class RNSVGImageComponentDescriptor final void adopt(ShadowNode::Unshared const &shadowNode) const override { ConcreteComponentDescriptor::adopt(shadowNode); - auto imageShadowNode = - std::static_pointer_cast(shadowNode); + auto &imageShadowNode = static_cast(*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: