diff --git a/build_system/clerk_driver.ml b/build_system/clerk_driver.ml index 1302c7b7..afc0ab3b 100644 --- a/build_system/clerk_driver.ml +++ b/build_system/clerk_driver.ml @@ -240,7 +240,7 @@ let get_lang file = Option.bind (Re.exec_opt catala_suffix_regex file) @@ fun g -> List.assoc_opt (Re.Group.get g 1) Cli.languages -let scan_tree (dir : File.t) : catala_build_item list = +let scan_tree (dir : File.t) : catala_build_item Seq.t = File.scan_tree (fun f -> match get_lang f with @@ -602,7 +602,7 @@ let collect_in_folder | Some (test_file_name, ninja) -> ninja, test_file_names ^ " $\n " ^ test_file_name in - List.fold_left + Seq.fold_left (fun acc (file, lang) -> let acc = collect collect_all_ninja_build acc file lang in collect collect_inline_ninja_builds acc file lang) diff --git a/compiler/catala_utils/file.ml b/compiler/catala_utils/file.ml index f350824c..b7743ee5 100644 --- a/compiler/catala_utils/file.ml +++ b/compiler/catala_utils/file.ml @@ -132,17 +132,20 @@ let scan_tree f t = false in let not_hidden t = match t.[0] with '.' | '_' -> false | _ -> true in - let rec do_dir acc d = - let items = Sys.readdir d |> Array.map (fun t -> d / t) |> Array.to_list in - do_files acc items - and do_files acc flist = + let rec do_dir d = + Sys.readdir d + |> Array.to_list + |> List.filter not_hidden + |> List.map (fun t -> d / t) + |> do_files + and do_files flist = let dirs, files = flist - |> List.filter not_hidden |> List.sort (fun a b -> -compare a b) |> List.partition is_dir in - let acc = List.rev_append (List.filter_map f files) acc in - List.fold_left do_dir acc dirs + Seq.append + (Seq.concat (Seq.map do_dir (List.to_seq dirs))) + (Seq.filter_map f (List.to_seq files)) in - do_dir [] t + do_dir t diff --git a/compiler/catala_utils/file.mli b/compiler/catala_utils/file.mli index ab3b0e03..a1ddfd49 100644 --- a/compiler/catala_utils/file.mli +++ b/compiler/catala_utils/file.mli @@ -105,7 +105,7 @@ val format : Format.formatter -> t -> unit (** Formats a filename in a consistent style, with double-quotes and color (when the output supports) *) -val scan_tree : (t -> 'a option) -> t -> 'a list +val scan_tree : (t -> 'a option) -> t -> 'a Seq.t (** Recursively scans a directory for files. Directories or files matching ".*" or "_*" are ignored. Unreadable files or subdirectories are ignored with a debug message. *)