Skip to content

Commit

Permalink
fix: props are no longer unnecesarily copied in new architecture (#2163)
Browse files Browse the repository at this point in the history
React Native no longer allows implicit copying of Props, since they're large data-structures and copies are often accidental (facebook/react-native@bbc517c). This updates react-native-svg to be compatible with this change, and will provide a small perf win.
  • Loading branch information
javache authored Oct 25, 2023
1 parent 5208a2f commit 694572a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions apple/Utils/RNSVGFabricConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import <React/RCTFabricComponentsPlugins.h>

template <typename T>
RNSVGBrush *brushFromColorStruct(T fillObject)
RNSVGBrush *brushFromColorStruct(const T &fillObject)
{
int type = fillObject.type;

Expand Down Expand Up @@ -43,7 +43,7 @@ RNSVGBrush *brushFromColorStruct(T fillObject)
}

template <typename T>
void setCommonNodeProps(T nodeProps, RNSVGNode *node)
void setCommonNodeProps(const T &nodeProps, RNSVGNode *node)
{
node.name = RCTNSStringFromStringNilIfEmpty(nodeProps.name);
node.opacity = nodeProps.opacity;
Expand Down Expand Up @@ -87,7 +87,7 @@ void setCommonNodeProps(T nodeProps, RNSVGNode *node)
node.accessibilityLabel = RCTNSStringFromStringNilIfEmpty(nodeProps.accessibilityLabel);
}

static NSMutableArray<RNSVGLength *> *createLengthArrayFromStrings(std::vector<std::string> stringArray)
static NSMutableArray<RNSVGLength *> *createLengthArrayFromStrings(const std::vector<std::string> &stringArray)
{
if (stringArray.empty()) {
return nil;
Expand All @@ -101,7 +101,7 @@ static NSMutableArray<RNSVGLength *> *createLengthArrayFromStrings(std::vector<s
}

template <typename T>
void setCommonRenderableProps(T renderableProps, RNSVGRenderable *renderableNode)
void setCommonRenderableProps(const T &renderableProps, RNSVGRenderable *renderableNode)
{
setCommonNodeProps(renderableProps, renderableNode);
renderableNode.fill = brushFromColorStruct(renderableProps.fill);
Expand Down Expand Up @@ -132,7 +132,7 @@ void setCommonRenderableProps(T renderableProps, RNSVGRenderable *renderableNode
}
}

static void addValueToDict(NSMutableDictionary *dict, std::string value, NSString *key)
static void addValueToDict(NSMutableDictionary *dict, const std::string &value, NSString *key)
{
NSString *valueOrNil = RCTNSStringFromStringNilIfEmpty(value);
if (valueOrNil) {
Expand All @@ -141,7 +141,7 @@ static void addValueToDict(NSMutableDictionary *dict, std::string value, NSStrin
}

template <typename T>
NSDictionary *parseFontStruct(T fontStruct)
NSDictionary *parseFontStruct(const T &fontStruct)
{
NSMutableDictionary *fontDict = [NSMutableDictionary new];

Expand All @@ -164,7 +164,7 @@ NSDictionary *parseFontStruct(T fontStruct)
}

template <typename T>
void setCommonGroupProps(T groupProps, RNSVGGroup *groupNode)
void setCommonGroupProps(const T &groupProps, RNSVGGroup *groupNode)
{
setCommonRenderableProps(groupProps, groupNode);

Expand All @@ -183,7 +183,7 @@ void setCommonGroupProps(T groupProps, RNSVGGroup *groupNode)
}

template <typename T>
void setCommonTextProps(T textProps, RNSVGText *textNode)
void setCommonTextProps(const T &textProps, RNSVGText *textNode)
{
setCommonGroupProps(textProps, textNode);
textNode.deltaX = createLengthArrayFromStrings(textProps.dx);
Expand Down

0 comments on commit 694572a

Please sign in to comment.