mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-05-05 17:04:25 -04:00
add Byte_buffer.copy, fix bugs
This commit is contained in:
parent
0ad561a8e7
commit
c02c76eb0b
2 changed files with 10 additions and 3 deletions
|
|
@ -96,7 +96,7 @@ let fold_left f acc self =
|
|||
|
||||
(* capture current content *)
|
||||
let acc = ref acc in
|
||||
for i = 0 to len do
|
||||
for i = 0 to len - 1 do
|
||||
acc := f !acc (Bytes.unsafe_get bs i)
|
||||
done;
|
||||
!acc
|
||||
|
|
@ -104,16 +104,20 @@ let fold_left f acc self =
|
|||
let[@inline] iter f self =
|
||||
(* capture current content *)
|
||||
let { bs; len } = self in
|
||||
for i = 0 to len do
|
||||
for i = 0 to len - 1 do
|
||||
f (Bytes.unsafe_get bs i)
|
||||
done
|
||||
|
||||
let[@inline] iteri f self =
|
||||
let { bs; len } = self in
|
||||
for i = 0 to len do
|
||||
for i = 0 to len - 1 do
|
||||
f i (Bytes.unsafe_get bs i)
|
||||
done
|
||||
|
||||
let copy self =
|
||||
let bs = Bytes.copy self.bs in
|
||||
{ bs; len = self.len }
|
||||
|
||||
let of_seq seq =
|
||||
let self = create ~cap:32 () in
|
||||
append_seq self seq;
|
||||
|
|
|
|||
|
|
@ -91,6 +91,9 @@ val to_slice : t -> CCByte_slice.t
|
|||
The slice shares the same byte array as [buf] (until [buf] is resized).
|
||||
@since 3.13.1 *)
|
||||
|
||||
val copy : t -> t
|
||||
(** [copy buf] returns an independent copy of [buf]. *)
|
||||
|
||||
val contents : t -> string
|
||||
(** Copy the internal data to a string. Allocates. *)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue