Skip to content

Commit

Permalink
Move efficient concat to stdlib
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
  • Loading branch information
rgrinberg committed Jun 5, 2018
1 parent babaea1 commit add85c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/action.ml
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,6 @@ let prog_and_args_of_values p ~dir =

module SW = String_with_vars

let concat = function
| [] -> ""
| [x] -> x
| xs -> String.concat ~sep:"" xs

module Unexpanded = struct
module type Uast = Action_intf.Ast
with type program = String_with_vars.t
Expand Down Expand Up @@ -693,7 +688,7 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
exec t ~ectx ~dir ~stdout_to ~stderr_to
~env:(Env.add env ~var ~value)
| Redirect (Stdout, fn, Echo s) ->
Io.write_file fn (concat s);
Io.write_file fn (String.concat s ~sep:"");
Fiber.return ()
| Redirect (outputs, fn, Run (Ok prog, args)) ->
let out = Process.File fn in
Expand All @@ -710,7 +705,7 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
redirect ~ectx ~dir outputs Config.dev_null t ~env ~stdout_to ~stderr_to
| Progn l ->
exec_list l ~ectx ~dir ~env ~stdout_to ~stderr_to
| Echo strs -> exec_echo stdout_to (concat strs)
| Echo strs -> exec_echo stdout_to (String.concat strs ~sep:"")
| Cat fn ->
Io.with_file_in fn ~f:(fun ic ->
let oc =
Expand Down
5 changes: 5 additions & 0 deletions src/stdune/string.ml
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,8 @@ let enumerate_gen s =

let enumerate_and = enumerate_gen "and"
let enumerate_or = enumerate_gen "or"

let concat ~sep = function
| [] -> ""
| [x] -> x
| xs -> concat ~sep xs

0 comments on commit add85c7

Please sign in to comment.