From bd6ffcafe3621b9f286726f381347f588ab0b017 Mon Sep 17 00:00:00 2001 From: Mikael Sand Date: Sun, 10 Mar 2019 03:39:30 +0200 Subject: [PATCH] [js] optimize object allocations --- elements/TSpan.js | 30 ++++++++------------ elements/Text.js | 30 ++++++++------------ elements/TextPath.js | 65 +++++++++++++++++++++----------------------- 3 files changed, 55 insertions(+), 70 deletions(-) diff --git a/elements/TSpan.js b/elements/TSpan.js index 18524fde..94872861 100644 --- a/elements/TSpan.js +++ b/elements/TSpan.js @@ -15,29 +15,23 @@ export default class TSpan extends Shape { props.matrix = matrix; } const prop = propsAndStyles(props); - const text = pickNotNil(extractText(prop, false)); - this.root.setNativeProps({ - ...prop, - ...text, - }); + Object.assign(prop, pickNotNil(extractText(prop, false))); + this.root.setNativeProps(prop); }; render() { const prop = propsAndStyles(this.props); - return ( - + const props = extractProps( + { + ...prop, + x: null, + y: null, + }, + this, ); + Object.assign(props, extractText(prop, false)); + props.ref = this.refMethod; + return ; } } diff --git a/elements/Text.js b/elements/Text.js index 2fcb7801..24a586cd 100644 --- a/elements/Text.js +++ b/elements/Text.js @@ -16,29 +16,23 @@ export default class Text extends Shape { props.matrix = matrix; } const prop = propsAndStyles(props); - const text = pickNotNil(extractText(prop, true)); - this.root.setNativeProps({ - ...prop, - ...text, - }); + Object.assign(prop, pickNotNil(extractText(prop, true))); + this.root.setNativeProps(prop); }; render() { const prop = propsAndStyles(this.props); - return ( - + const props = extractProps( + { + ...prop, + x: null, + y: null, + }, + this, ); + Object.assign(props, extractText(prop, true)); + props.ref = this.refMethod; + return ; } } diff --git a/elements/TextPath.js b/elements/TextPath.js index 3ba7a754..7d2ddd2c 100644 --- a/elements/TextPath.js +++ b/elements/TextPath.js @@ -15,11 +15,8 @@ export default class TextPath extends Shape { if (matrix) { props.matrix = matrix; } - const text = pickNotNil(extractText(props, true)); - this.root.setNativeProps({ - ...props, - ...text, - }); + Object.assign(props, pickNotNil(extractText(props, true))); + this.root.setNativeProps(props); }; render() { @@ -27,45 +24,45 @@ export default class TextPath extends Shape { children, xlinkHref, href = xlinkHref, - startOffset, + startOffset = 0, method, spacing, side, alignmentBaseline, midLine, - ...props + ...prop } = this.props; const matched = href && href.match(idPattern); const match = matched && matched[1]; if (match) { - return ( - + const props = extractProps( + { + ...propsAndStyles(prop), + x: null, + y: null, + }, + this, ); + Object.assign( + props, + extractText( + { + children, + }, + true, + ), + { + href: match, + startOffset, + method, + spacing, + side, + alignmentBaseline, + midLine, + }, + ); + props.ref = this.refMethod; + return ; } console.warn(