perf: avoid unnecessary shared_ptr copies in Fabric components (#2164)

Ports the upstream best-practice around props handling of shared_ptr in a855013fc6
This commit is contained in:
Pieter De Baets
2023-10-25 11:23:14 +01:00
committed by GitHub
parent a5dae2f54d
commit 5208a2f6a7
21 changed files with 22 additions and 23 deletions

View File

@@ -39,7 +39,7 @@ using namespace facebook::react;
- (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);
}

View File

@@ -41,7 +41,7 @@ using namespace facebook::react;
- (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)]

View File

@@ -43,7 +43,7 @@ using namespace facebook::react;
- (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);

View File

@@ -72,7 +72,7 @@ using namespace facebook::react;
- (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)];

View File

@@ -40,7 +40,7 @@ using namespace facebook::react;
- (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)];

View File

@@ -42,7 +42,7 @@ using namespace facebook::react;
- (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)];

View File

@@ -41,7 +41,7 @@ using namespace facebook::react;
- (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)];

View File

@@ -41,7 +41,7 @@ using namespace facebook::react;
- (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);

View File

@@ -41,7 +41,7 @@ using namespace facebook::react;
- (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)];

View File

@@ -38,7 +38,7 @@ using namespace facebook::react;
- (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)];

View File

@@ -64,7 +64,7 @@ using namespace facebook::react;
- (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;

View File

@@ -39,7 +39,7 @@ using namespace facebook::react;
- (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;

View File

@@ -40,7 +40,7 @@ using namespace facebook::react;
- (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)];

View File

@@ -40,7 +40,7 @@ using namespace facebook::react;
- (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)];

View File

@@ -40,7 +40,7 @@ using namespace facebook::react;
- (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)];

View File

@@ -40,7 +40,7 @@ using namespace facebook::react;
- (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)];

View File

@@ -40,7 +40,7 @@ using namespace facebook::react;
- (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)];

View File

@@ -58,7 +58,7 @@ using namespace facebook::react;
- (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);

View File

@@ -49,7 +49,7 @@ using namespace facebook::react;
- (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);

View File

@@ -39,7 +39,7 @@ using namespace facebook::react;
- (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);

View File

@@ -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: