Skip to content

Commit 65fcccc

Browse files
committed
only Up is needed, optimize a special case of Upto
1 parent 3224ba8 commit 65fcccc

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

jscomp/core/js_dump.ml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ let pp_direction f (direction : J.for_direction) =
267267
match direction with
268268
| Up
269269
| Upto -> P.string f L.plus_plus
270-
| Down
271270
| Downto -> P.string f L.minus_minus
272271

273272
let return_sp f =
@@ -1181,10 +1180,6 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
11811180
let (_,_,right) = Js_op_util.op_prec Ge in
11821181
P.string f L.ge ;
11831182
right
1184-
| Down ->
1185-
let (_,_,right) = Js_op_util.op_prec Gt in
1186-
P.string f L.gt ;
1187-
right
11881183
in
11891184
P.space f ;
11901185
let cxt =

jscomp/core/js_op.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ type direction_flag =
188188
| Upto
189189
| Downto
190190
| Up
191-
| Down
191+
192192
(*
193193
{[
194194
let rec x = 1 :: y

jscomp/core/lam_compile.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,11 +1606,11 @@ and compile_lambda
16061606
| Lwhile(p,body) ->
16071607
compile_while p body lambda_cxt
16081608
| Lfor (id,start,finish,direction,body) ->
1609-
begin match direction with
1610-
| Upto ->
1611-
compile_for id start finish Upto body lambda_cxt
1612-
| Downto ->
1613-
compile_for id start finish Downto body lambda_cxt
1609+
begin match direction,finish with
1610+
| Upto, Lprim {primitive = Psubint ; args = [ new_finish ; Lconst (Const_int 1) ]} ->
1611+
compile_for id start new_finish Up body lambda_cxt
1612+
| _ ->
1613+
compile_for id start finish (if direction = Upto then Upto else Downto) body lambda_cxt
16141614
end
16151615
| Lassign(id,lambda) ->
16161616
compile_assign id lambda lambda_cxt

0 commit comments

Comments
 (0)