diff options
| author | Emilio Jesus Gallego Arias | 2019-01-23 12:10:28 +0100 |
|---|---|---|
| committer | Emilio Jesus Gallego Arias | 2019-01-23 12:10:28 +0100 |
| commit | 163000a8326ad559d2a0581608f2ccc83fe3beee (patch) | |
| tree | 0959e061af8f2812537e80df0e5ac90df7912137 | |
| parent | c845fed94ab68f7891e08d0a8aabc1a7ddff11eb (diff) | |
| parent | 4baa950b79589c6617770b5612bd082fde9c9255 (diff) | |
Merge PR #9361: Make prvect tail recursive (fix #9355)
Ack-by: SkySkimmer
Reviewed-by: ejgallego
| -rw-r--r-- | lib/pp.ml | 13 | ||||
| -rw-r--r-- | test-suite/unit-tests/lib/pp_big_vect.ml | 14 |
2 files changed, 19 insertions, 8 deletions
@@ -284,15 +284,12 @@ let pr_vertical_list pr = function [pr 0 a0 ++ sep() ++ ... ++ sep() ++ pr n an] *) let prvecti_with_sep sep elem v = - let rec pr i = - if Int.equal i 0 then - elem 0 v.(0) - else - let r = pr (i-1) and s = sep () and e = elem i v.(i) in - r ++ s ++ e + let v = CArray.mapi (fun i x -> + let pp = if i = 0 then mt() else sep() in + pp ++ elem i x) + v in - let n = Array.length v in - if Int.equal n 0 then mt () else pr (n - 1) + seq (Array.to_list v) (* [prvecti pr [|a0 ; ... ; an|]] outputs [pr 0 a0 ++ ... ++ pr n an] *) diff --git a/test-suite/unit-tests/lib/pp_big_vect.ml b/test-suite/unit-tests/lib/pp_big_vect.ml new file mode 100644 index 0000000000..e1cdd290e2 --- /dev/null +++ b/test-suite/unit-tests/lib/pp_big_vect.ml @@ -0,0 +1,14 @@ +open OUnit +open Pp + +let pr_big_vect = + let n = "pr_big_vect" in + n >:: (fun () -> + let v = Array.make (1 lsl 20) () in + let pp = prvecti_with_sep spc (fun _ _ -> str"x") v in + let str = string_of_ppcmds pp in + ignore(str)) + +let tests = [pr_big_vect] + +let () = Utest.run_tests __FILE__ (Utest.open_log_out_ch __FILE__) tests |
