Open
Description
The following code (without an optional field)
type t = {
a: string,
b: int
}
let x = { a: "test", b: 1 }
let y = { ...x, b: 5 }
let f = x => { ...x, b: x.b + 1 }
is compiled to
var y = {
a: "test",
b: 5
};
function f(x) {
return {
a: x.a,
b: x.b + 1 | 0
};
}
var x = {
a: "test",
b: 1
};
However, as soon as I make a
an optional field, the output changes to the more inefficient
var x = {
a: "test",
b: 1
};
var newrecord = Caml_obj.obj_dup(x);
newrecord.b = 5;
function f(x) {
var newrecord = Caml_obj.obj_dup(x);
newrecord.b = x.b + 1 | 0;
return newrecord;
}
var y = newrecord;
Metadata
Metadata
Assignees
Labels
No labels