Skip to content

Commit 66c4ebf

Browse files
committed
codegen micro-tweak
1 parent 2ba3f2b commit 66c4ebf

File tree

9 files changed

+23
-11
lines changed

9 files changed

+23
-11
lines changed

jscomp/core/lam_compile.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,10 @@ and compile_lambda
16071607
compile_while p body lambda_cxt
16081608
| Lfor (id,start,finish,direction,body) ->
16091609
begin match direction,finish with
1610-
| Upto, Lprim {primitive = Psubint ; args = [ new_finish ; Lconst (Const_int 1) ]} ->
1610+
| Upto,
1611+
(Lprim {primitive = Psubint ; args = [ new_finish ; Lconst (Const_int 1) ]} |
1612+
Lprim {primitive = Poffsetint (-1); args = [ new_finish ; ]}
1613+
) ->
16111614
compile_for id start new_finish Up body lambda_cxt
16121615
| _ ->
16131616
compile_for id start finish (if direction = Upto then Upto else Downto) body lambda_cxt

jscomp/test/bench.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function init(l, f) {
3030
];
3131
}
3232
var res = Caml_array.caml_make_vect(l, f$1(0));
33-
for(var i = 1 ,i_finish = l - 1 | 0; i <= i_finish; ++i){
33+
for(var i = 1; i < l; ++i){
3434
res[i] = f$1(i);
3535
}
3636
return res;

jscomp/test/earger_curry_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function init(l, f) {
3232
];
3333
}
3434
var res = Caml_array.caml_make_vect(l, f$1(0));
35-
for(var i = 1 ,i_finish = l - 1 | 0; i <= i_finish; ++i){
35+
for(var i = 1; i < l; ++i){
3636
res[i] = f$1(i);
3737
}
3838
return res;

jscomp/test/ext_string_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function is_empty(s) {
238238
function repeat(n, s) {
239239
var len = s.length;
240240
var res = Caml_bytes.caml_create_bytes(Caml_int32.imul(n, len));
241-
for(var i = 0 ,i_finish = n - 1 | 0; i <= i_finish; ++i){
241+
for(var i = 0; i < n; ++i){
242242
$$String.blit(s, 0, res, Caml_int32.imul(i, len), len);
243243
}
244244
return Bytes.to_string(res);

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404897,7 +404897,10 @@ and compile_lambda
404897404897
compile_while p body lambda_cxt
404898404898
| Lfor (id,start,finish,direction,body) ->
404899404899
begin match direction,finish with
404900-
| Upto, Lprim {primitive = Psubint ; args = [ new_finish ; Lconst (Const_int 1) ]} ->
404900+
| Upto,
404901+
(Lprim {primitive = Psubint ; args = [ new_finish ; Lconst (Const_int 1) ]} |
404902+
Lprim {primitive = Poffsetint (-1); args = [ new_finish ; ]}
404903+
) ->
404901404904
compile_for id start new_finish Up body lambda_cxt
404902404905
| _ ->
404903404906
compile_for id start finish (if direction = Upto then Upto else Downto) body lambda_cxt

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404897,7 +404897,10 @@ and compile_lambda
404897404897
compile_while p body lambda_cxt
404898404898
| Lfor (id,start,finish,direction,body) ->
404899404899
begin match direction,finish with
404900-
| Upto, Lprim {primitive = Psubint ; args = [ new_finish ; Lconst (Const_int 1) ]} ->
404900+
| Upto,
404901+
(Lprim {primitive = Psubint ; args = [ new_finish ; Lconst (Const_int 1) ]} |
404902+
Lprim {primitive = Poffsetint (-1); args = [ new_finish ; ]}
404903+
) ->
404901404904
compile_for id start new_finish Up body lambda_cxt
404902404905
| _ ->
404903404906
compile_for id start finish (if direction = Upto then Upto else Downto) body lambda_cxt

lib/4.06.1/whole_compiler.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398843,7 +398843,10 @@ and compile_lambda
398843398843
compile_while p body lambda_cxt
398844398844
| Lfor (id,start,finish,direction,body) ->
398845398845
begin match direction,finish with
398846-
| Upto, Lprim {primitive = Psubint ; args = [ new_finish ; Lconst (Const_int 1) ]} ->
398846+
| Upto,
398847+
(Lprim {primitive = Psubint ; args = [ new_finish ; Lconst (Const_int 1) ]} |
398848+
Lprim {primitive = Poffsetint (-1); args = [ new_finish ; ]}
398849+
) ->
398847398850
compile_for id start new_finish Up body lambda_cxt
398848398851
| _ ->
398849398852
compile_for id start finish (if direction = Upto then Upto else Downto) body lambda_cxt

lib/es6/array.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ function init(l, f) {
2222
];
2323
}
2424
var res = Caml_array.caml_make_vect(l, Curry._1(f, 0));
25-
for(var i = 1 ,i_finish = l - 1 | 0; i <= i_finish; ++i){
25+
for(var i = 1; i < l; ++i){
2626
res[i] = Curry._1(f, i);
2727
}
2828
return res;
2929
}
3030

3131
function make_matrix(sx, sy, init) {
3232
var res = Caml_array.caml_make_vect(sx, []);
33-
for(var x = 0 ,x_finish = sx - 1 | 0; x <= x_finish; ++x){
33+
for(var x = 0; x < sx; ++x){
3434
res[x] = Caml_array.caml_make_vect(sy, init);
3535
}
3636
return res;

lib/js/array.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ function init(l, f) {
2222
];
2323
}
2424
var res = Caml_array.caml_make_vect(l, Curry._1(f, 0));
25-
for(var i = 1 ,i_finish = l - 1 | 0; i <= i_finish; ++i){
25+
for(var i = 1; i < l; ++i){
2626
res[i] = Curry._1(f, i);
2727
}
2828
return res;
2929
}
3030

3131
function make_matrix(sx, sy, init) {
3232
var res = Caml_array.caml_make_vect(sx, []);
33-
for(var x = 0 ,x_finish = sx - 1 | 0; x <= x_finish; ++x){
33+
for(var x = 0; x < sx; ++x){
3434
res[x] = Caml_array.caml_make_vect(sy, init);
3535
}
3636
return res;

0 commit comments

Comments
 (0)