Skip to content

Commit 2e65b7c

Browse files
committed
inline toInt as well
1 parent eed1f88 commit 2e65b7c

File tree

3 files changed

+9
-31
lines changed

3 files changed

+9
-31
lines changed

jscomp/others/js_mapperRt.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424

2525

2626

27-
28-
let toInt (i : int) (xs : int array) =
29-
Js.Array2.unsafe_get xs i
30-
3127
let rec fromIntAux (enum : int) i len xs =
3228
if i = len then None
3329
else

jscomp/others/js_mapperRt.mli

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@
2424

2525

2626

27-
28-
(**
29-
[toInt enum array]
30-
Based on the value of [enum], return its mapped int
31-
*)
32-
val toInt :
33-
int -> int array -> int
3427

3528
(**
3629
[fromInt len array int]

jscomp/syntax/ast_derive_js_mapper.ml

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let unsafeIndexGet =
7676
(Val.mk ~prim:[""] {loc = noloc; txt = unsafeIndex} ~attrs:[Ast_attributes.bs_get_index]
7777
(Ast_compatible.arrow (Typ.var "b") (Ast_compatible.arrow (Typ.var "a") (Typ.var "c")))
7878
)
79-
79+
let unsafeIndexGetExp = (Exp.ident {loc = noloc; txt = Lident unsafeIndex})
8080
(* JavaScript has allowed trailing commas in array literals since the beginning,
8181
and later added them to object literals (ECMAScript 5) and most recently (ECMAScript 2017)
8282
to function parameters. *)
@@ -136,21 +136,10 @@ let (&&~) a b =
136136
app2 (Exp.ident {loc = noloc; txt = Ldot(Lident "Pervasives","&&")})
137137
a b
138138
let (->~) a b = Ast_compatible.arrow a b
139+
139140
let jsMapperRt =
140141
Longident.Ldot (Lident "Js", "MapperRt")
141142

142-
143-
144-
145-
146-
147-
let toInt exp array =
148-
app2
149-
(Exp.ident
150-
{ loc=noloc;
151-
txt = Longident.Ldot (jsMapperRt, "toInt")})
152-
(eraseType exp)
153-
array
154143
let fromInt len array exp =
155144
app3
156145
(Exp.ident
@@ -276,7 +265,7 @@ let init () =
276265
let expMap = Exp.ident {loc; txt = Lident map} in
277266
let revExpMap = Exp.ident {loc ; txt = Lident revMap} in
278267
let data, revData, has_bs_as = buildMap row_fields in
279-
let exp_get = (Exp.ident {loc ; txt = Lident unsafeIndex}) in
268+
280269
let v = [
281270
eraseTypeStr;
282271
unsafeIndexGet;
@@ -290,7 +279,7 @@ let init () =
290279
else expMap);
291280
toJsBody
292281
(if has_bs_as then
293-
app2 exp_get expMap exp_param
282+
app2 unsafeIndexGetExp expMap exp_param
294283
else app1 eraseTypeExp exp_param)
295284
;
296285
Ast_comb.single_non_rec_value
@@ -299,7 +288,7 @@ let init () =
299288
(Pat.var pat_param)
300289
(
301290
app2
302-
exp_get
291+
unsafeIndexGetExp
303292
revExpMap
304293
exp_param
305294
)
@@ -323,17 +312,17 @@ let init () =
323312
let constantArrayExp = Exp.ident {loc; txt = Lident constantArray} in
324313
let exp_len = Ast_compatible.const_exp_int (List.length ctors) in
325314
let v = [
315+
unsafeIndexGet;
326316
eraseTypeStr;
327317
Ast_comb.single_non_rec_value
328318
{loc; txt = constantArray}
329319
(Ast_compatible.const_exp_int_list_as_array xs)
330320
;
331321
toJsBody
332322
(
333-
coerceResultToNewType @@
334-
toInt
335-
exp_param
336-
constantArrayExp
323+
app2 unsafeIndexGetExp
324+
constantArrayExp
325+
exp_param
337326
)
338327
;
339328
Ast_comb.single_non_rec_value

0 commit comments

Comments
 (0)