mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
more efficient CCString.init
This commit is contained in:
parent
352b7e3901
commit
b8b0cc3645
2 changed files with 7 additions and 3 deletions
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue