@@ -1491,6 +1491,12 @@ val iter :
1491
1491
'a array ->
1492
1492
('a -> unit) ->
1493
1493
unit
1494
+
1495
+ val fold_left :
1496
+ 'b array ->
1497
+ 'a ->
1498
+ ('a -> 'b -> 'a) ->
1499
+ 'a
1494
1500
end = struct
1495
1501
#1 "ext_array.ml"
1496
1502
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -1751,6 +1757,15 @@ let iter a f =
1751
1757
let open Array in
1752
1758
for i = 0 to length a - 1 do f(unsafe_get a i) done
1753
1759
1760
+
1761
+ let fold_left a x f =
1762
+ let open Array in
1763
+ let r = ref x in
1764
+ for i = 0 to length a - 1 do
1765
+ r := f !r (unsafe_get a i)
1766
+ done;
1767
+ !r
1768
+
1754
1769
end
1755
1770
module Ext_list : sig
1756
1771
#1 "ext_list.mli"
@@ -3367,7 +3382,7 @@ let add_list (xs : _ list ) init =
3367
3382
let of_list xs = add_list xs empty
3368
3383
3369
3384
let of_array xs =
3370
- Array .fold_left (fun acc (k,v) -> add acc k v ) empty xs
3385
+ Ext_array .fold_left xs empty (fun acc (k,v) -> add acc k v )
3371
3386
3372
3387
end
3373
3388
module Ext_json_types
@@ -4411,7 +4426,7 @@ let rec bucket_length accu = function
4411
4426
4412
4427
let stats h =
4413
4428
let mbl =
4414
- Array .fold_left (fun m b -> max m (bucket_length 0 b)) 0 h.data in
4429
+ Ext_array .fold_left h.data 0 (fun m b -> max m (bucket_length 0 b)) in
4415
4430
let histo = Array.make (mbl + 1) 0 in
4416
4431
Ext_array.iter h.data
4417
4432
(fun b ->
@@ -8954,7 +8969,7 @@ let of_list l =
8954
8969
| _ -> of_sorted_list (List.sort_uniq compare_elt l)
8955
8970
8956
8971
let of_array l =
8957
- Array .fold_left (fun acc x -> add acc x ) empty l
8972
+ Ext_array .fold_left l empty (fun acc x -> add acc x )
8958
8973
8959
8974
(* also check order *)
8960
8975
let invariant t =
@@ -9660,7 +9675,7 @@ let handle_empty_sources
9660
9675
let files_array = Lazy.force file_array in
9661
9676
let dyn_file_array = String_vec.make (Array.length files_array) in
9662
9677
let files =
9663
- Array .fold_left (fun acc name ->
9678
+ Ext_array .fold_left files_array !cur_sources (fun acc name ->
9664
9679
if is_input_or_output generators name then acc
9665
9680
else
9666
9681
match Ext_string.is_valid_source_name name with
@@ -9674,7 +9689,7 @@ let handle_empty_sources
9674
9689
warning_unused_file name dir ;
9675
9690
acc
9676
9691
| Suffix_mismatch -> acc
9677
- ) !cur_sources files_array in
9692
+ ) in
9678
9693
cur_sources := files ;
9679
9694
[ Ext_file_pp.patch_action dyn_file_array
9680
9695
loc_start loc_end
@@ -9830,7 +9845,7 @@ let rec
9830
9845
| None -> (* No setting on [!files]*)
9831
9846
(** We should avoid temporary files *)
9832
9847
cur_sources :=
9833
- Array .fold_left (fun acc name ->
9848
+ Ext_array .fold_left (Lazy.force file_array) !cur_sources (fun acc name ->
9834
9849
if is_input_or_output generators name then
9835
9850
acc
9836
9851
else
@@ -9844,7 +9859,7 @@ let rec
9844
9859
;
9845
9860
acc
9846
9861
| Suffix_mismatch -> acc
9847
- ) !cur_sources (Lazy.force file_array) ;
9862
+ ) ;
9848
9863
cur_globbed_dirs := [dir]
9849
9864
| Some (Arr ({content = [||] }as empty_json_array)) ->
9850
9865
(* [ ] populatd by scanning the dir (just once) *)
@@ -9858,12 +9873,12 @@ let rec
9858
9873
TODO: still need check?
9859
9874
*)
9860
9875
cur_sources :=
9861
- Array .fold_left (fun acc (s : Ext_json_types.t) ->
9876
+ Ext_array .fold_left sx !cur_sources (fun acc s ->
9862
9877
match s with
9863
9878
| Str {str = s} ->
9864
9879
Bsb_db.collect_module_by_filename ~dir acc s
9865
9880
| _ -> acc
9866
- ) !cur_sources sx
9881
+ )
9867
9882
| Some (Obj {map = m; loc} ) -> (* { excludes : [], slow_re : "" }*)
9868
9883
cur_globbed_dirs := [dir];
9869
9884
let excludes =
@@ -9882,11 +9897,11 @@ let rec
9882
9897
fun name -> Str.string_match re name 0 && not (List.mem name excludes)
9883
9898
| Some x, _ -> Bsb_exception.errorf ~loc "slow-re expect a string literal"
9884
9899
| None , _ -> Bsb_exception.errorf ~loc "missing field: slow-re" in
9885
- cur_sources := Array .fold_left (fun acc name ->
9900
+ cur_sources := Ext_array .fold_left (Lazy.force file_array) !cur_sources (fun acc name ->
9886
9901
if is_input_or_output generators name || not (predicate name) then acc
9887
9902
else
9888
9903
Bsb_db.collect_module_by_filename ~dir acc name
9889
- ) !cur_sources (Lazy.force file_array)
9904
+ )
9890
9905
| Some x -> Bsb_exception.config_error x "files field expect array or object "
9891
9906
end;
9892
9907
let cur_sources = !cur_sources in
@@ -9900,7 +9915,7 @@ let rec
9900
9915
| Some (True _), _ ->
9901
9916
let root = cxt.root in
9902
9917
let parent = Filename.concat root dir in
9903
- Array .fold_left (fun origin x ->
9918
+ Ext_array .fold_left (Lazy.force file_array) Bsb_file_groups.empty (fun origin x ->
9904
9919
if Sys.is_directory (Filename.concat parent x) then
9905
9920
Bsb_file_groups.merge
9906
9921
(
@@ -9911,7 +9926,7 @@ let rec
9911
9926
traverse = true
9912
9927
} String_map.empty) origin
9913
9928
else origin
9914
- ) Bsb_file_groups.empty (Lazy.force file_array)
9929
+ )
9915
9930
(* readdir parent avoiding scanning twice *)
9916
9931
| None, false
9917
9932
| Some (False _), _ -> Bsb_file_groups.empty
@@ -9971,10 +9986,9 @@ and parsing_single_source ({not_dev; dir_index ; cwd} as cxt ) (x : Ext_json_typ
9971
9986
cwd= Ext_path.concat cwd dir} map
9972
9987
| _ -> Bsb_file_groups.empty
9973
9988
and parsing_arr_sources cxt (file_groups : Ext_json_types.t array) =
9974
- Array .fold_left (fun origin x ->
9989
+ Ext_array .fold_left file_groups Bsb_file_groups.empty (fun origin x ->
9975
9990
Bsb_file_groups.merge (parsing_single_source cxt x) origin
9976
- ) Bsb_file_groups.empty file_groups
9977
-
9991
+ )
9978
9992
and parse_sources ( cxt : cxt) (sources : Ext_json_types.t ) =
9979
9993
match sources with
9980
9994
| Arr file_groups ->
@@ -10833,7 +10847,7 @@ let elements set =
10833
10847
10834
10848
let stats h =
10835
10849
let mbl =
10836
- Array .fold_left (fun m b -> max m (List.length b)) 0 h.data in
10850
+ Ext_array .fold_left h.data 0 (fun m b -> max m (List.length b)) in
10837
10851
let histo = Array.make (mbl + 1) 0 in
10838
10852
Ext_array.iter h.data
10839
10853
(fun b ->
@@ -11809,8 +11823,8 @@ let interpret_json
11809
11823
|? (Bsb_build_schemas.cut_generators, `Bool (fun b -> cut_generators := b))
11810
11824
|? (Bsb_build_schemas.generators, `Arr (fun s ->
11811
11825
generators :=
11812
- Array .fold_left (fun acc json ->
11813
- match ( json : Ext_json_types.t) with
11826
+ Ext_array .fold_left s String_map.empty (fun acc json ->
11827
+ match json with
11814
11828
| Obj {map = m ; loc} ->
11815
11829
begin match String_map.find_opt m Bsb_build_schemas.name,
11816
11830
String_map.find_opt m Bsb_build_schemas.command with
@@ -11819,7 +11833,7 @@ let interpret_json
11819
11833
| _, _ ->
11820
11834
Bsb_exception.errorf ~loc {| generators exepect format like { "name" : "cppo", "command" : "cppo $in -o $out"} |}
11821
11835
end
11822
- | _ -> acc ) String_map.empty s ))
11836
+ | _ -> acc ) ))
11823
11837
|? (Bsb_build_schemas.refmt_flags, `Arr (fun s -> refmt_flags := get_list_string s))
11824
11838
|? (Bsb_build_schemas.entries, `Arr (fun s -> entries := parse_entries s))
11825
11839
|> ignore ;
0 commit comments