more efficient CCString.init

This commit is contained in:
Simon Cruanes 2014-12-18 14:05:12 +01:00
parent 352b7e3901
commit b8b0cc3645
2 changed files with 7 additions and 3 deletions

View file

@ -62,9 +62,8 @@ let init = String.init
#else #else
let init n f = let init n f =
let buf = Buffer.create n in let buf = Bytes.init n f in
for i = 0 to n-1 do Buffer.add_char buf (f i) done; Bytes.unsafe_to_string buf
Buffer.contents buf
#endif #endif

View file

@ -66,6 +66,11 @@ val init : int -> (int -> char) -> string
(** Analog to [Array.init]. (** Analog to [Array.init].
@since 0.3.3 *) @since 0.3.3 *)
(*$T
init 3 (fun i -> [|'a'; 'b'; 'c'|].(i)) = "abc"
init 0 (fun _ -> assert false) = ""
*)
val of_gen : char gen -> string val of_gen : char gen -> string
val of_seq : char sequence -> string val of_seq : char sequence -> string
val of_klist : char klist -> string val of_klist : char klist -> string