Skip to content

Commit d1cdc16

Browse files
committed
specialize string_of_int
1 parent ffe0981 commit d1cdc16

File tree

133 files changed

+731
-728
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+731
-728
lines changed

jscomp/all.depend

+2-2
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,8 @@ core/lam_compile_main.cmx : ext/literals.cmx core/lam_util.cmx \
675675
core/js_exp_make.cmx core/js_dump_program.cmx common/js_config.cmx \
676676
core/js_cmj_format.cmx core/j.cmx ext/ident_set.cmx ext/ext_string.cmx \
677677
ext/ext_pervasives.cmx ext/ext_path.cmx ext/ext_namespace.cmx \
678-
common/ext_log.cmx ext/ext_list.cmx ext/ext_ident.cmx \
679-
ext/ext_filename.cmx ext/ext_char.cmx core/lam_compile_main.cmi
678+
common/ext_log.cmx ext/ext_list.cmx ext/ext_filename.cmx ext/ext_char.cmx \
679+
core/lam_compile_main.cmi
680680
core/js_implementation.cmx : core/ocaml_parse.cmx ext/literals.cmx \
681681
core/lam_compile_main.cmx core/lam_compile_env.cmx common/js_config.cmx \
682682
ext/ext_string.cmx ext/ext_pervasives.cmx ext/ext_namespace.cmx \

jscomp/core/lam_compile_main.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.t)
7171
Note the arity of [print_endline] is already analyzed before,
7272
so it should be safe
7373
*)
74-
| Single(_, ({name="string_of_int";_} as id),_ ), "pervasives.ml" ->
74+
(* | Single(_, ({name="string_of_int";_} as id),_ ), "pervasives.ml" ->
7575
Js_output.of_stmt @@ S.alias_variable id
7676
~exp:(
7777
let arg = Ext_ident.create "param" in
7878
E.ocaml_fun [arg] [S.return_stmt (E.int_to_string (E.var arg))]
79-
)
79+
) *)
8080

8181
(** Special handling for values in [Sys] *)
8282
| Single(_, ({name="max_array_length" | "max_string_length";_} as id) ,_ ), "sys.ml" ->

jscomp/stdlib/pervasives.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,12 @@ let bool_of_string = function
244244
| "false" -> false
245245
| _ -> invalid_arg "bool_of_string"
246246

247+
#if BS then
248+
external string_of_int : int -> string = "String" [@@bs.val]
249+
#else
247250
let string_of_int n =
248251
format_int "%d" n
249-
252+
#end
250253
external int_of_string : string -> int = "caml_int_of_string"
251254
external string_get : string -> int -> char = "%string_safe_get"
252255

jscomp/stdlib/pervasives.mli

+4-1
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,12 @@ val bool_of_string : string -> bool
568568
Raise [Invalid_argument "bool_of_string"] if the string is not
569569
["true"] or ["false"]. *)
570570

571+
#if BS then
572+
external string_of_int : int -> string = "String" [@@bs.val]
573+
#else
571574
val string_of_int : int -> string
572575
(** Return the string representation of an integer, in decimal. *)
573-
576+
#end
574577
external int_of_string : string -> int = "caml_int_of_string"
575578
(** Convert the given string to an integer.
576579
The string is read in decimal (by default) or in hexadecimal (if it

jscomp/test/a_filename_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function eq(loc, x, y) {
1313
test_id[0] = test_id[0] + 1 | 0;
1414
suites[0] = /* :: */[
1515
/* tuple */[
16-
loc + (" id " + test_id[0]),
16+
loc + (" id " + String(test_id[0])),
1717
(function () {
1818
return /* Eq */Block.__(0, [
1919
x,

jscomp/test/a_scope_bug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function odd(_z) {
77
var z = _z;
88
var even = Caml_int32.imul(z, z);
99
var a = (even + 4 | 0) + even | 0;
10-
console.log("" + a);
10+
console.log(String(a));
1111
_z = 32;
1212
continue ;
1313

jscomp/test/arity_deopt.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function eq(loc, x, y) {
1212
test_id[0] = test_id[0] + 1 | 0;
1313
suites[0] = /* :: */[
1414
/* tuple */[
15-
loc + (" id " + test_id[0]),
15+
loc + (" id " + String(test_id[0])),
1616
(function () {
1717
return /* Eq */Block.__(0, [
1818
x,

jscomp/test/array_subtle_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function eq(loc, param) {
1515
test_id[0] = test_id[0] + 1 | 0;
1616
suites[0] = /* :: */[
1717
/* tuple */[
18-
loc + (" id " + test_id[0]),
18+
loc + (" id " + String(test_id[0])),
1919
(function () {
2020
return /* Eq */Block.__(0, [
2121
x,

jscomp/test/ast_abstract_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function eq(loc, x, y) {
1212
test_id[0] = test_id[0] + 1 | 0;
1313
suites[0] = /* :: */[
1414
/* tuple */[
15-
loc + (" id " + test_id[0]),
15+
loc + (" id " + String(test_id[0])),
1616
(function () {
1717
return /* Eq */Block.__(0, [
1818
x,

jscomp/test/ast_js_mapper_poly_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function eq(loc, x, y) {
1313
test_id[0] = test_id[0] + 1 | 0;
1414
suites[0] = /* :: */[
1515
/* tuple */[
16-
loc + (" id " + test_id[0]),
16+
loc + (" id " + String(test_id[0])),
1717
(function () {
1818
return /* Eq */Block.__(0, [
1919
x,

jscomp/test/ast_mapper_defensive_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function $$throw(loc, x) {
1212
test_id[0] = test_id[0] + 1 | 0;
1313
suites[0] = /* :: */[
1414
/* tuple */[
15-
loc + (" id " + test_id[0]),
15+
loc + (" id " + String(test_id[0])),
1616
(function () {
1717
return /* ThrowAny */Block.__(7, [x]);
1818
})

jscomp/test/bs_array_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function neq(loc, x, y) {
3232
test_id[0] = test_id[0] + 1 | 0;
3333
suites[0] = /* :: */[
3434
/* tuple */[
35-
loc + (" id " + test_id[0]),
35+
loc + (" id " + String(test_id[0])),
3636
(function () {
3737
return /* Neq */Block.__(1, [
3838
x,

jscomp/test/bs_auto_uncurry_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function eq(loc, x, y) {
1111
test_id[0] = test_id[0] + 1 | 0;
1212
suites[0] = /* :: */[
1313
/* tuple */[
14-
loc + (" id " + test_id[0]),
14+
loc + (" id " + String(test_id[0])),
1515
(function () {
1616
return /* Eq */Block.__(0, [
1717
x,

jscomp/test/bs_hashtbl_string_test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ function bench() {
7070
function bench2(m) {
7171
var empty = Belt_HashMap.make(1000000, m);
7272
for(var i = 0; i <= 1000000; ++i){
73-
Belt_HashMap.set(empty, "" + i, i);
73+
Belt_HashMap.set(empty, String(i), i);
7474
}
7575
for(var i$1 = 0; i$1 <= 1000000; ++i$1){
76-
if (!Belt_HashMap.has(empty, "" + i$1)) {
76+
if (!Belt_HashMap.has(empty, String(i$1))) {
7777
throw [
7878
Caml_builtin_exceptions.assert_failure,
7979
[
@@ -86,7 +86,7 @@ function bench2(m) {
8686

8787
}
8888
for(var i$2 = 0; i$2 <= 1000000; ++i$2){
89-
Belt_HashMap.remove(empty, "" + i$2);
89+
Belt_HashMap.remove(empty, String(i$2));
9090
}
9191
if (empty.size === 0) {
9292
return 0;
@@ -110,10 +110,10 @@ function bench3(m) {
110110
var cmp = m[/* cmp */0];
111111
var table = empty.data;
112112
for(var i = 0; i <= 1000000; ++i){
113-
table = Belt_MapDict.set(table, "" + i, i, cmp);
113+
table = Belt_MapDict.set(table, String(i), i, cmp);
114114
}
115115
for(var i$1 = 0; i$1 <= 1000000; ++i$1){
116-
if (!Belt_MapDict.has(table, "" + i$1, cmp)) {
116+
if (!Belt_MapDict.has(table, String(i$1), cmp)) {
117117
throw [
118118
Caml_builtin_exceptions.assert_failure,
119119
[
@@ -126,7 +126,7 @@ function bench3(m) {
126126

127127
}
128128
for(var i$2 = 0; i$2 <= 1000000; ++i$2){
129-
table = Belt_MapDict.remove(table, "" + i$2, cmp);
129+
table = Belt_MapDict.remove(table, String(i$2), cmp);
130130
}
131131
if (Belt_MapDict.size(table) === 0) {
132132
return 0;
@@ -147,10 +147,10 @@ var Sx = Belt_Id.comparable(Caml_primitive.caml_string_compare);
147147
function bench4() {
148148
var table = Belt_internalBucketsType.make(/* () */0, /* () */0, 1000000);
149149
for(var i = 0; i <= 1000000; ++i){
150-
Belt_HashMapString.set(table, "" + i, i);
150+
Belt_HashMapString.set(table, String(i), i);
151151
}
152152
for(var i$1 = 0; i$1 <= 1000000; ++i$1){
153-
if (!Belt_HashMapString.has(table, "" + i$1)) {
153+
if (!Belt_HashMapString.has(table, String(i$1))) {
154154
throw [
155155
Caml_builtin_exceptions.assert_failure,
156156
[
@@ -163,7 +163,7 @@ function bench4() {
163163

164164
}
165165
for(var i$2 = 0; i$2 <= 1000000; ++i$2){
166-
Belt_HashMapString.remove(table, "" + i$2);
166+
Belt_HashMapString.remove(table, String(i$2));
167167
}
168168
if (Belt_HashMapString.isEmpty(table)) {
169169
return 0;

jscomp/test/bs_ignore_effect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function eq(loc, x, y) {
1111
test_id[0] = test_id[0] + 1 | 0;
1212
suites[0] = /* :: */[
1313
/* tuple */[
14-
loc + (" id " + test_id[0]),
14+
loc + (" id " + String(test_id[0])),
1515
(function () {
1616
return /* Eq */Block.__(0, [
1717
x,

jscomp/test/bs_list_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ eq("File \"bs_list_test.ml\", line 259, characters 5-12", Belt_List.has(/* :: */
16651665
]
16661666
]
16671667
], "2", (function (x, s) {
1668-
return +("" + x === s);
1668+
return +(String(x) === s);
16691669
})), /* true */1);
16701670

16711671
eq("File \"bs_list_test.ml\", line 260, characters 5-12", Belt_List.has(/* :: */[
@@ -1678,7 +1678,7 @@ eq("File \"bs_list_test.ml\", line 260, characters 5-12", Belt_List.has(/* :: */
16781678
]
16791679
]
16801680
], "0", (function (x, s) {
1681-
return +("" + x === s);
1681+
return +(String(x) === s);
16821682
})), /* false */0);
16831683

16841684
b("File \"bs_list_test.ml\", line 262, characters 4-11", +(Belt_List.reduceReverse(/* :: */[

jscomp/test/bs_map_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function eq(loc, x, y) {
1414
test_id[0] = test_id[0] + 1 | 0;
1515
suites[0] = /* :: */[
1616
/* tuple */[
17-
loc + (" id " + test_id[0]),
17+
loc + (" id " + String(test_id[0])),
1818
(function () {
1919
return /* Eq */Block.__(0, [
2020
x,
@@ -31,7 +31,7 @@ function b(loc, v) {
3131
test_id[0] = test_id[0] + 1 | 0;
3232
suites[0] = /* :: */[
3333
/* tuple */[
34-
loc + (" id " + test_id[0]),
34+
loc + (" id " + String(test_id[0])),
3535
(function () {
3636
return /* Ok */Block.__(4, [v]);
3737
})

jscomp/test/bs_string_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function eq(loc, x, y) {
1111
test_id[0] = test_id[0] + 1 | 0;
1212
suites[0] = /* :: */[
1313
/* tuple */[
14-
loc + (" id " + test_id[0]),
14+
loc + (" id " + String(test_id[0])),
1515
(function () {
1616
return /* Eq */Block.__(0, [
1717
x,

jscomp/test/buffer_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var suites_001 = /* :: */[
4848
(function () {
4949
var v = Buffer.create(30);
5050
for(var i = 0; i <= 10; ++i){
51-
Buffer.add_string(v, "" + i);
51+
Buffer.add_string(v, String(i));
5252
}
5353
return /* Eq */Block.__(0, [
5454
Buffer.contents(v),

jscomp/test/bytes_split_gpr_743_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function eq(loc, param) {
1515
test_id[0] = test_id[0] + 1 | 0;
1616
suites[0] = /* :: */[
1717
/* tuple */[
18-
loc + (" id " + test_id[0]),
18+
loc + (" id " + String(test_id[0])),
1919
(function () {
2020
return /* Eq */Block.__(0, [
2121
x,

jscomp/test/caml_sys_poly_fill_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function eq(loc, x, y) {
1313
test_id[0] = test_id[0] + 1 | 0;
1414
suites[0] = /* :: */[
1515
/* tuple */[
16-
loc + (" id " + test_id[0]),
16+
loc + (" id " + String(test_id[0])),
1717
(function () {
1818
return /* Eq */Block.__(0, [
1919
x,

jscomp/test/chain_code_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function eq(loc, x, y) {
1111
test_id[0] = test_id[0] + 1 | 0;
1212
suites[0] = /* :: */[
1313
/* tuple */[
14-
loc + (" id " + test_id[0]),
14+
loc + (" id " + String(test_id[0])),
1515
(function () {
1616
return /* Eq */Block.__(0, [
1717
x,

jscomp/test/chn_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function eq(loc, x, y) {
1414
test_id[0] = test_id[0] + 1 | 0;
1515
suites[0] = /* :: */[
1616
/* tuple */[
17-
loc + (" id " + test_id[0]),
17+
loc + (" id " + String(test_id[0])),
1818
(function () {
1919
return /* Eq */Block.__(0, [
2020
x,

jscomp/test/class3_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function eq(loc, x, y) {
6969
test_id[0] = test_id[0] + 1 | 0;
7070
suites[0] = /* :: */[
7171
/* tuple */[
72-
loc + (" id " + test_id[0]),
72+
loc + (" id " + String(test_id[0])),
7373
(function () {
7474
return /* Eq */Block.__(0, [
7575
x,

jscomp/test/class4_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function eq(loc, x, y) {
2626
test_id[0] = test_id[0] + 1 | 0;
2727
suites[0] = /* :: */[
2828
/* tuple */[
29-
loc + (" id " + test_id[0]),
29+
loc + (" id " + String(test_id[0])),
3030
(function () {
3131
return /* Eq */Block.__(0, [
3232
x,

jscomp/test/class5_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function eq(loc, x, y) {
2828
test_id[0] = test_id[0] + 1 | 0;
2929
suites[0] = /* :: */[
3030
/* tuple */[
31-
loc + (" id " + test_id[0]),
31+
loc + (" id " + String(test_id[0])),
3232
(function () {
3333
return /* Eq */Block.__(0, [
3434
x,
@@ -63,7 +63,7 @@ function printable_point_init($$class) {
6363
}),
6464
print,
6565
(function (self$1) {
66-
return "" + Curry._1(self$1[0][get_x], self$1);
66+
return String(Curry._1(self$1[0][get_x], self$1));
6767
})
6868
]);
6969
return (function (_, self, x_init) {
@@ -240,7 +240,7 @@ eq("File \"class5_test.ml\", line 67, characters 5-12", /* tuple */[
240240
return x + y | 0;
241241
}), 0),
242242
Caml_oo_curry.js3(-1010803711, 6, l$1, (function (s, x) {
243-
return s + (x + " ");
243+
return s + (String(x) + " ");
244244
}), "")
245245
]);
246246

jscomp/test/class6_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function eq(loc, x, y) {
2626
test_id[0] = test_id[0] + 1 | 0;
2727
suites[0] = /* :: */[
2828
/* tuple */[
29-
loc + (" id " + test_id[0]),
29+
loc + (" id " + String(test_id[0])),
3030
(function () {
3131
return /* Eq */Block.__(0, [
3232
x,

jscomp/test/class7_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function eq(loc, x, y) {
4040
test_id[0] = test_id[0] + 1 | 0;
4141
suites[0] = /* :: */[
4242
/* tuple */[
43-
loc + (" id " + test_id[0]),
43+
loc + (" id " + String(test_id[0])),
4444
(function () {
4545
return /* Eq */Block.__(0, [
4646
x,

jscomp/test/class_fib_open_recursion_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function eq(loc, x, y) {
1818
test_id[0] = test_id[0] + 1 | 0;
1919
suites[0] = /* :: */[
2020
/* tuple */[
21-
loc + (" id " + test_id[0]),
21+
loc + (" id " + String(test_id[0])),
2222
(function () {
2323
return /* Eq */Block.__(0, [
2424
x,

jscomp/test/complex_while_loop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function f() {
1313
};
1414
return +(fib(n) > 10);
1515
})()) {
16-
console.log("" + n);
16+
console.log(String(n));
1717
n = n + 1 | 0;
1818
};
1919
return /* () */0;

jscomp/test/condition_compilation_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function eq(loc, x, y) {
1717
test_id[0] = test_id[0] + 1 | 0;
1818
suites[0] = /* :: */[
1919
/* tuple */[
20-
loc + (" id " + test_id[0]),
20+
loc + (" id " + String(test_id[0])),
2121
(function () {
2222
return /* Eq */Block.__(0, [
2323
x,

jscomp/test/div_by_zero_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function eq(loc, x, y) {
1313
test_id[0] = test_id[0] + 1 | 0;
1414
suites[0] = /* :: */[
1515
/* tuple */[
16-
loc + (" id " + test_id[0]),
16+
loc + (" id " + String(test_id[0])),
1717
(function () {
1818
return /* Eq */Block.__(0, [
1919
x,

0 commit comments

Comments
 (0)