diff --git a/CHANGELOG.md b/CHANGELOG.md index 5478d7fa96..5d67dcbaed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ - Untagged variants: Support `promise`, RegExes, Dates, File and Blob. https://github.com/rescript-lang/rescript-compiler/pull/6383 - Support aliased types as payloads to untagged variants. https://github.com/rescript-lang/rescript-compiler/pull/6394 +#### :nail_care: Polish + +- A little performance improvement for JSX V4 runtime helper by removing one object allocation for components with key prop. https://github.com/rescript-lang/rescript-compiler/pull/6376 + # 11.0.0-rc.3 #### :bug: Bug Fix diff --git a/jscomp/others/jsxPPXReactSupportC.res b/jscomp/others/jsxPPXReactSupportC.res index 9049fc47df..4930472ed4 100644 --- a/jscomp/others/jsxPPXReactSupportC.res +++ b/jscomp/others/jsxPPXReactSupportC.res @@ -26,12 +26,12 @@ module Jsx = JsxC %%private( @val - external propsWithKey: (@as(json`{}`) _, 'props, {"key": string}) => 'props = "Object.assign" + external propsWithKey: ({"key": string}, 'props) => 'props = "Object.assign" @inline let addKeyProp = (~key: option=?, p: 'props): 'props => switch key { - | Some(key) => propsWithKey(p, {"key": key}) + | Some(key) => propsWithKey({"key": key}, p) | None => p } ) diff --git a/jscomp/others/jsxPPXReactSupportU.res b/jscomp/others/jsxPPXReactSupportU.res index f35c1911c3..8987f68e4d 100644 --- a/jscomp/others/jsxPPXReactSupportU.res +++ b/jscomp/others/jsxPPXReactSupportU.res @@ -26,12 +26,12 @@ module Jsx = JsxU %%private( @val - external propsWithKey: (@as(json`{}`) _, 'props, {"key": string}) => 'props = "Object.assign" + external propsWithKey: ({"key": string}, 'props) => 'props = "Object.assign" @inline let addKeyProp = (~key: option=?, p: 'props): 'props => switch key { - | Some(key) => propsWithKey(p, {"key": key}) + | Some(key) => propsWithKey({"key": key}, p) | None => p } ) diff --git a/lib/es6/jsxPPXReactSupportC.js b/lib/es6/jsxPPXReactSupportC.js index 1ddf8ffe99..3a19f4851e 100644 --- a/lib/es6/jsxPPXReactSupportC.js +++ b/lib/es6/jsxPPXReactSupportC.js @@ -4,17 +4,17 @@ import * as React from "react"; import * as Caml_splice_call from "./caml_splice_call.js"; function createElementWithKey(key, component, props) { - return React.createElement(component, key !== undefined ? Object.assign({}, props, { + return React.createElement(component, key !== undefined ? Object.assign({ key: key - }) : props); + }, props) : props); } function createElementVariadicWithKey(key, component, props, elements) { return Caml_splice_call.spliceApply(React.createElement, [ component, - key !== undefined ? Object.assign({}, props, { + key !== undefined ? Object.assign({ key: key - }) : props, + }, props) : props, elements ]); } diff --git a/lib/es6/jsxPPXReactSupportU.js b/lib/es6/jsxPPXReactSupportU.js index 1ddf8ffe99..3a19f4851e 100644 --- a/lib/es6/jsxPPXReactSupportU.js +++ b/lib/es6/jsxPPXReactSupportU.js @@ -4,17 +4,17 @@ import * as React from "react"; import * as Caml_splice_call from "./caml_splice_call.js"; function createElementWithKey(key, component, props) { - return React.createElement(component, key !== undefined ? Object.assign({}, props, { + return React.createElement(component, key !== undefined ? Object.assign({ key: key - }) : props); + }, props) : props); } function createElementVariadicWithKey(key, component, props, elements) { return Caml_splice_call.spliceApply(React.createElement, [ component, - key !== undefined ? Object.assign({}, props, { + key !== undefined ? Object.assign({ key: key - }) : props, + }, props) : props, elements ]); } diff --git a/lib/js/jsxPPXReactSupportC.js b/lib/js/jsxPPXReactSupportC.js index 5c42e89375..d9016af5c6 100644 --- a/lib/js/jsxPPXReactSupportC.js +++ b/lib/js/jsxPPXReactSupportC.js @@ -4,17 +4,17 @@ var React = require("react"); var Caml_splice_call = require("./caml_splice_call.js"); function createElementWithKey(key, component, props) { - return React.createElement(component, key !== undefined ? Object.assign({}, props, { + return React.createElement(component, key !== undefined ? Object.assign({ key: key - }) : props); + }, props) : props); } function createElementVariadicWithKey(key, component, props, elements) { return Caml_splice_call.spliceApply(React.createElement, [ component, - key !== undefined ? Object.assign({}, props, { + key !== undefined ? Object.assign({ key: key - }) : props, + }, props) : props, elements ]); } diff --git a/lib/js/jsxPPXReactSupportU.js b/lib/js/jsxPPXReactSupportU.js index 5c42e89375..d9016af5c6 100644 --- a/lib/js/jsxPPXReactSupportU.js +++ b/lib/js/jsxPPXReactSupportU.js @@ -4,17 +4,17 @@ var React = require("react"); var Caml_splice_call = require("./caml_splice_call.js"); function createElementWithKey(key, component, props) { - return React.createElement(component, key !== undefined ? Object.assign({}, props, { + return React.createElement(component, key !== undefined ? Object.assign({ key: key - }) : props); + }, props) : props); } function createElementVariadicWithKey(key, component, props, elements) { return Caml_splice_call.spliceApply(React.createElement, [ component, - key !== undefined ? Object.assign({}, props, { + key !== undefined ? Object.assign({ key: key - }) : props, + }, props) : props, elements ]); }