Skip to content

Commit 44d84ea

Browse files
committed
optimize Array.map
1 parent 5859409 commit 44d84ea

File tree

9 files changed

+761
-49
lines changed

9 files changed

+761
-49
lines changed

jscomp/js_dump.ml

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,19 @@ let rec pp_function method_
320320
match b.J.expression_desc with
321321
| Var (Id i) -> Ident.same a i
322322
| _ -> false) l ls ->
323+
let optimize len p cxt f v =
324+
if p then
325+
begin
326+
P.string f Js_config.curry;
327+
P.string f L.dot;
328+
P.string f "__";
329+
P.string f (Printf.sprintf "%d" len);
330+
P.paren_group f 1 (fun _ -> arguments cxt f [function_])
331+
end
332+
else
333+
vident cxt f v
334+
in
335+
let len = List.length l in (* length *)
323336
begin match name with
324337
| Some i ->
325338
P.string f L.var;
@@ -328,35 +341,15 @@ let rec pp_function method_
328341
P.space f ;
329342
P.string f L.eq;
330343
P.space f ;
331-
if arity = NA then
332-
let len = List.length l in (* length *)
333-
begin
334-
P.string f Js_config.curry;
335-
P.string f L.dot;
336-
P.string f "__";
337-
P.string f (Printf.sprintf "%d" len);
338-
P.paren_group f 1 (fun _ -> arguments cxt f [function_])
339-
end
340-
else
341-
vident cxt f v
344+
345+
optimize len (arity = NA && len <= 8) cxt f v
342346
| None ->
343347
if return then
344348
begin
345349
P.string f L.return ;
346350
P.space f;
347351
end;
348-
if arity = NA then
349-
let len = List.length l in (* length *)
350-
begin
351-
P.string f Js_config.curry;
352-
P.string f L.dot;
353-
P.string f "__";
354-
P.string f (Printf.sprintf "%d" len);
355-
P.paren_group f 1 (fun _ -> arguments cxt f [function_])
356-
end
357-
358-
else
359-
vident cxt f v
352+
optimize len (arity = NA && len <=8) cxt f v
360353
end
361354
| _, _ ->
362355

jscomp/test/.depend

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ basic_module_test.cmx : ../stdlib/set.cmx pr6726.cmx offset.cmx \
7575
mt_global.cmx mt.cmx basic_module_test.cmi
7676
bdd.cmj : ../stdlib/array.cmi
7777
bdd.cmx : ../stdlib/array.cmx
78+
bench.cmj : ../stdlib/array.cmi
79+
bench.cmx : ../stdlib/array.cmx
7880
bigarray_test.cmj : ../stdlib/int32.cmi ../stdlib/complex.cmi \
7981
../stdlib/bigarray.cmi
8082
bigarray_test.cmx : ../stdlib/int32.cmx ../stdlib/complex.cmx \
@@ -163,8 +165,8 @@ digest_test.cmx : ../stdlib/string.cmx ../stdlib/printf.cmx mt.cmx \
163165
ext_array.cmx ../stdlib/digest.cmx ../stdlib/array.cmx
164166
div_by_zero_test.cmj : mt.cmi ../stdlib/int64.cmi ../stdlib/int32.cmi
165167
div_by_zero_test.cmx : mt.cmx ../stdlib/int64.cmx ../stdlib/int32.cmx
166-
earger_curry_test.cmj :
167-
earger_curry_test.cmx :
168+
earger_curry_test.cmj : ../stdlib/array.cmi
169+
earger_curry_test.cmx : ../stdlib/array.cmx
168170
empty_obj.cmj :
169171
empty_obj.cmx :
170172
epsilon_test.cmj : mt.cmi
@@ -843,6 +845,8 @@ basic_module_test.cmj : ../stdlib/set.cmj pr6726.cmj offset.cmj \
843845
mt_global.cmj mt.cmj basic_module_test.cmi
844846
bdd.cmo : ../stdlib/array.cmi
845847
bdd.cmj : ../stdlib/array.cmj
848+
bench.cmo : ../stdlib/array.cmi
849+
bench.cmj : ../stdlib/array.cmj
846850
bigarray_test.cmo : ../stdlib/int32.cmi ../stdlib/complex.cmi \
847851
../stdlib/bigarray.cmi
848852
bigarray_test.cmj : ../stdlib/int32.cmj ../stdlib/complex.cmj \
@@ -931,8 +935,8 @@ digest_test.cmj : ../stdlib/string.cmj ../stdlib/printf.cmj mt.cmj \
931935
ext_array.cmj ../stdlib/digest.cmj ../stdlib/array.cmj
932936
div_by_zero_test.cmo : mt.cmi ../stdlib/int64.cmi ../stdlib/int32.cmi
933937
div_by_zero_test.cmj : mt.cmj ../stdlib/int64.cmj ../stdlib/int32.cmj
934-
earger_curry_test.cmo :
935-
earger_curry_test.cmj :
938+
earger_curry_test.cmo : ../stdlib/array.cmi
939+
earger_curry_test.cmj : ../stdlib/array.cmj
936940
empty_obj.cmo :
937941
empty_obj.cmj :
938942
epsilon_test.cmo : mt.cmi

jscomp/test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ OTHERS := literals a test_ari test_export2 test_internalOO test_obj_simple_ffi t
6060
bs_rest_test infer_type_test fs_test module_as_function\
6161
test_case_set test_mutliple string_bound_get_test inline_string_test\
6262
ppx_this_obj_test unsafe_obj_external gpr_627_test jsoo_485_test jsoo_400_test \
63-
test_require more_uncurry earger_curry_test poly_type
63+
test_require more_uncurry earger_curry_test poly_type bench
6464

6565

6666

jscomp/test/bench.1.js

Lines changed: 226 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)