Skip to content

Commit 0974127

Browse files
authored
Jsx ppx optimize object allocation (#6376)
1 parent fd08faa commit 0974127

7 files changed

+24
-20
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
- Untagged variants: Support `promise`, RegExes, Dates, File and Blob. https://github.com/rescript-lang/rescript-compiler/pull/6383
2020
- Support aliased types as payloads to untagged variants. https://github.com/rescript-lang/rescript-compiler/pull/6394
2121

22+
#### :nail_care: Polish
23+
24+
- 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
25+
2226
# 11.0.0-rc.3
2327

2428
#### :bug: Bug Fix

jscomp/others/jsxPPXReactSupportC.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ module Jsx = JsxC
2626

2727
%%private(
2828
@val
29-
external propsWithKey: (@as(json`{}`) _, 'props, {"key": string}) => 'props = "Object.assign"
29+
external propsWithKey: ({"key": string}, 'props) => 'props = "Object.assign"
3030

3131
@inline
3232
let addKeyProp = (~key: option<string>=?, p: 'props): 'props =>
3333
switch key {
34-
| Some(key) => propsWithKey(p, {"key": key})
34+
| Some(key) => propsWithKey({"key": key}, p)
3535
| None => p
3636
}
3737
)

jscomp/others/jsxPPXReactSupportU.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ module Jsx = JsxU
2626

2727
%%private(
2828
@val
29-
external propsWithKey: (@as(json`{}`) _, 'props, {"key": string}) => 'props = "Object.assign"
29+
external propsWithKey: ({"key": string}, 'props) => 'props = "Object.assign"
3030

3131
@inline
3232
let addKeyProp = (~key: option<string>=?, p: 'props): 'props =>
3333
switch key {
34-
| Some(key) => propsWithKey(p, {"key": key})
34+
| Some(key) => propsWithKey({"key": key}, p)
3535
| None => p
3636
}
3737
)

lib/es6/jsxPPXReactSupportC.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import * as React from "react";
44
import * as Caml_splice_call from "./caml_splice_call.js";
55

66
function createElementWithKey(key, component, props) {
7-
return React.createElement(component, key !== undefined ? Object.assign({}, props, {
7+
return React.createElement(component, key !== undefined ? Object.assign({
88
key: key
9-
}) : props);
9+
}, props) : props);
1010
}
1111

1212
function createElementVariadicWithKey(key, component, props, elements) {
1313
return Caml_splice_call.spliceApply(React.createElement, [
1414
component,
15-
key !== undefined ? Object.assign({}, props, {
15+
key !== undefined ? Object.assign({
1616
key: key
17-
}) : props,
17+
}, props) : props,
1818
elements
1919
]);
2020
}

lib/es6/jsxPPXReactSupportU.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import * as React from "react";
44
import * as Caml_splice_call from "./caml_splice_call.js";
55

66
function createElementWithKey(key, component, props) {
7-
return React.createElement(component, key !== undefined ? Object.assign({}, props, {
7+
return React.createElement(component, key !== undefined ? Object.assign({
88
key: key
9-
}) : props);
9+
}, props) : props);
1010
}
1111

1212
function createElementVariadicWithKey(key, component, props, elements) {
1313
return Caml_splice_call.spliceApply(React.createElement, [
1414
component,
15-
key !== undefined ? Object.assign({}, props, {
15+
key !== undefined ? Object.assign({
1616
key: key
17-
}) : props,
17+
}, props) : props,
1818
elements
1919
]);
2020
}

lib/js/jsxPPXReactSupportC.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ var React = require("react");
44
var Caml_splice_call = require("./caml_splice_call.js");
55

66
function createElementWithKey(key, component, props) {
7-
return React.createElement(component, key !== undefined ? Object.assign({}, props, {
7+
return React.createElement(component, key !== undefined ? Object.assign({
88
key: key
9-
}) : props);
9+
}, props) : props);
1010
}
1111

1212
function createElementVariadicWithKey(key, component, props, elements) {
1313
return Caml_splice_call.spliceApply(React.createElement, [
1414
component,
15-
key !== undefined ? Object.assign({}, props, {
15+
key !== undefined ? Object.assign({
1616
key: key
17-
}) : props,
17+
}, props) : props,
1818
elements
1919
]);
2020
}

lib/js/jsxPPXReactSupportU.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ var React = require("react");
44
var Caml_splice_call = require("./caml_splice_call.js");
55

66
function createElementWithKey(key, component, props) {
7-
return React.createElement(component, key !== undefined ? Object.assign({}, props, {
7+
return React.createElement(component, key !== undefined ? Object.assign({
88
key: key
9-
}) : props);
9+
}, props) : props);
1010
}
1111

1212
function createElementVariadicWithKey(key, component, props, elements) {
1313
return Caml_splice_call.spliceApply(React.createElement, [
1414
component,
15-
key !== undefined ? Object.assign({}, props, {
15+
key !== undefined ? Object.assign({
1616
key: key
17-
}) : props,
17+
}, props) : props,
1818
elements
1919
]);
2020
}

0 commit comments

Comments
 (0)