Skip to content

Commit 3bdcaa4

Browse files
committed
call runtime only when dividing by zero
1 parent 3407763 commit 3bdcaa4

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

jscomp/core/js_exp_make.ml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,16 +1265,22 @@ let bigint_comp (cmp : Lam_compat.comparison) ?comment (e0: t) (e1: t) =
12651265
bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1
12661266

12671267
let bigint_div ~checked ?comment (e0: t) (e1: t) =
1268-
if checked then
1269-
runtime_call Js_runtime_modules.bigint "div" [e0; e1]
1270-
else
1271-
bigint_op ?comment Div e0 e1
1268+
match e1.expression_desc with
1269+
| Number (Bigint { i = i1 }) when i1 = "0" || i1 = "-0" ->
1270+
if checked then
1271+
runtime_call Js_runtime_modules.bigint "div" [e0; e1]
1272+
else
1273+
bigint_op ?comment Div e0 e1
1274+
| _ -> bigint_op ?comment Div e0 e1
12721275

12731276
let bigint_mod ~checked ?comment (e0: t) (e1: t) =
1274-
if checked then
1275-
runtime_call Js_runtime_modules.bigint "mod_" [e0; e1]
1276-
else
1277-
bigint_op ?comment Mod e0 e1
1277+
match e1.expression_desc with
1278+
| Number (Bigint { i = i1 }) when i1 = "0" || i1 = "-0" ->
1279+
if checked then
1280+
runtime_call Js_runtime_modules.bigint "mod_" [e0; e1]
1281+
else
1282+
bigint_op ?comment Mod e0 e1
1283+
| _ -> bigint_op ?comment Mod e0 e1
12781284

12791285
(* TODO -- alpha conversion
12801286
remember to add parens..

0 commit comments

Comments
 (0)