Skip to content

Commit af81a58

Browse files
committed
Done: micro tweak the build instruction generation performance
1 parent d4685d2 commit af81a58

File tree

2 files changed

+64
-54
lines changed

2 files changed

+64
-54
lines changed

jscomp/bsb/bsb_ninja_gen.ml

+32-27
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ let output_static_resources
9696
let output_installation_file cwd_lib_bs namespace files_to_install =
9797
let install_oc = open_out_bin (cwd_lib_bs // "install.ninja") in
9898
let o s = output_string install_oc s in
99+
let[@inline] oo suffix ~dest ~src =
100+
o "o " ;
101+
o dest ;
102+
o suffix;
103+
o " : cp ";
104+
o src;
105+
o suffix; o "\n" in
99106
let bs = ".."//"bs" in
100107
let sb = ".."//".." in
101108
o "rule cp\n command = cp $i $out\n";
@@ -104,36 +111,34 @@ let output_installation_file cwd_lib_bs namespace files_to_install =
104111
let base = Filename.basename name_sans_extension in
105112
let ns_base = Ext_namespace_encode.make ?ns:namespace base in
106113
let ns_origin = Ext_namespace_encode.make ?ns:namespace name_sans_extension in
107-
let sources =
108-
match info, syntax_kind with
109-
| Intf , _ -> assert false
110-
| Impl, Ml -> [".ml" ]
111-
| Impl, Reason -> [".re" ]
112-
| Impl, Res -> [".res" ]
113-
| Impl_intf, Ml -> [".ml" ; ".mli"]
114-
| Impl_intf, Reason -> [".re" ; ".rei"]
115-
| Impl_intf, Res -> [".res" ; ".resi"]
116-
in
117-
let binaries =
118-
match info with
119-
| Intf -> assert false
120-
| Impl -> [".cmi"; ".cmt"; ".cmj"]
121-
| Impl_intf -> [".cmi"; ".cmt"; ".cmti" ; ".cmj"] in
122-
(* install source files *)
123-
Ext_list.iter sources (fun s ->
124-
o @@ Printf.sprintf "o %s : cp %s \n" (base ^ s) (sb // name_sans_extension ^s)
125-
126-
);
127-
(* install binary artifacts *)
128-
Ext_list.iter binaries (fun s ->
129-
o @@ Printf.sprintf "o %s : cp %s \n" (ns_base ^ s) (bs // ns_origin ^s)
130-
) );
114+
oo Literals.suffix_cmi ~dest:ns_base ~src:(bs//ns_origin);
115+
oo Literals.suffix_cmj ~dest:ns_base ~src:(bs//ns_origin);
116+
oo Literals.suffix_cmt ~dest:ns_base ~src:(bs//ns_origin);
117+
let suffix =
118+
match syntax_kind with
119+
| Ml -> Literals.suffix_ml
120+
| Reason -> Literals.suffix_re
121+
| Res -> Literals.suffix_res
122+
in oo suffix ~dest:base ~src:(sb//name_sans_extension);
123+
match info with
124+
| Intf -> assert false
125+
| Impl -> ()
126+
| Impl_intf ->
127+
let suffix_b =
128+
match syntax_kind with
129+
| Ml -> Literals.suffix_mli
130+
| Reason -> Literals.suffix_rei
131+
| Res -> Literals.suffix_resi in
132+
oo suffix_b ~dest:base ~src:(sb//name_sans_extension);
133+
oo Literals.suffix_cmti ~dest:ns_base ~src:(bs//ns_origin)
134+
);
131135
begin match namespace with
132136
| None -> ()
133137
| Some x ->
134-
o @@ Printf.sprintf "o %s.cmi : cp %s.cmi\n" x (bs//x);
135-
o @@ Printf.sprintf "o %s.cmj : cp %s.cmj\n" x (bs//x);
136-
o @@ Printf.sprintf "o %s.cmt : cp %s.cmt\n" x (bs//x)
138+
let src = bs // x in
139+
oo Literals.suffix_cmi ~dest:x ~src;
140+
oo Literals.suffix_cmj ~dest:x ~src;
141+
oo Literals.suffix_cmt ~dest:x ~src
137142
end;
138143
close_out install_oc
139144

lib/4.06.1/bsb.ml

+32-27
Original file line numberDiff line numberDiff line change
@@ -13550,6 +13550,13 @@ let output_static_resources
1355013550
let output_installation_file cwd_lib_bs namespace files_to_install =
1355113551
let install_oc = open_out_bin (cwd_lib_bs // "install.ninja") in
1355213552
let o s = output_string install_oc s in
13553+
let[@inline] oo suffix ~dest ~src =
13554+
o "o " ;
13555+
o dest ;
13556+
o suffix;
13557+
o " : cp ";
13558+
o src;
13559+
o suffix; o "\n" in
1355313560
let bs = ".."//"bs" in
1355413561
let sb = ".."//".." in
1355513562
o "rule cp\n command = cp $i $out\n";
@@ -13558,36 +13565,34 @@ let output_installation_file cwd_lib_bs namespace files_to_install =
1355813565
let base = Filename.basename name_sans_extension in
1355913566
let ns_base = Ext_namespace_encode.make ?ns:namespace base in
1356013567
let ns_origin = Ext_namespace_encode.make ?ns:namespace name_sans_extension in
13561-
let sources =
13562-
match info, syntax_kind with
13563-
| Intf , _ -> assert false
13564-
| Impl, Ml -> [".ml" ]
13565-
| Impl, Reason -> [".re" ]
13566-
| Impl, Res -> [".res" ]
13567-
| Impl_intf, Ml -> [".ml" ; ".mli"]
13568-
| Impl_intf, Reason -> [".re" ; ".rei"]
13569-
| Impl_intf, Res -> [".res" ; ".resi"]
13570-
in
13571-
let binaries =
13572-
match info with
13573-
| Intf -> assert false
13574-
| Impl -> [".cmi"; ".cmt"; ".cmj"]
13575-
| Impl_intf -> [".cmi"; ".cmt"; ".cmti" ; ".cmj"] in
13576-
(* install source files *)
13577-
Ext_list.iter sources (fun s ->
13578-
o @@ Printf.sprintf "o %s : cp %s \n" (base ^ s) (sb // name_sans_extension ^s)
13579-
13580-
);
13581-
(* install binary artifacts *)
13582-
Ext_list.iter binaries (fun s ->
13583-
o @@ Printf.sprintf "o %s : cp %s \n" (ns_base ^ s) (bs // ns_origin ^s)
13584-
) );
13568+
oo Literals.suffix_cmi ~dest:ns_base ~src:(bs//ns_origin);
13569+
oo Literals.suffix_cmj ~dest:ns_base ~src:(bs//ns_origin);
13570+
oo Literals.suffix_cmt ~dest:ns_base ~src:(bs//ns_origin);
13571+
let suffix =
13572+
match syntax_kind with
13573+
| Ml -> Literals.suffix_ml
13574+
| Reason -> Literals.suffix_re
13575+
| Res -> Literals.suffix_res
13576+
in oo suffix ~dest:base ~src:(sb//name_sans_extension);
13577+
match info with
13578+
| Intf -> assert false
13579+
| Impl -> ()
13580+
| Impl_intf ->
13581+
let suffix_b =
13582+
match syntax_kind with
13583+
| Ml -> Literals.suffix_mli
13584+
| Reason -> Literals.suffix_rei
13585+
| Res -> Literals.suffix_resi in
13586+
oo suffix_b ~dest:base ~src:(sb//name_sans_extension);
13587+
oo Literals.suffix_cmti ~dest:ns_base ~src:(bs//ns_origin)
13588+
);
1358513589
begin match namespace with
1358613590
| None -> ()
1358713591
| Some x ->
13588-
o @@ Printf.sprintf "o %s.cmi : cp %s.cmi\n" x (bs//x);
13589-
o @@ Printf.sprintf "o %s.cmj : cp %s.cmj\n" x (bs//x);
13590-
o @@ Printf.sprintf "o %s.cmt : cp %s.cmt\n" x (bs//x)
13592+
let src = bs // x in
13593+
oo Literals.suffix_cmi ~dest:x ~src;
13594+
oo Literals.suffix_cmj ~dest:x ~src;
13595+
oo Literals.suffix_cmt ~dest:x ~src
1359113596
end;
1359213597
close_out install_oc
1359313598

0 commit comments

Comments
 (0)