From f5aa4de6e774882aa656917b8f203905737c531f Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 13 May 2024 21:52:46 -0400 Subject: [PATCH] add CCByte_buffer.to_slice --- src/core/CCByte_buffer.ml | 1 + src/core/CCByte_buffer.mli | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/core/CCByte_buffer.ml b/src/core/CCByte_buffer.ml index 1bec0286..14795f83 100644 --- a/src/core/CCByte_buffer.ml +++ b/src/core/CCByte_buffer.ml @@ -89,6 +89,7 @@ let[@inline] contents self = Bytes.sub_string self.bs 0 self.len let[@inline] contents_bytes self = Bytes.sub self.bs 0 self.len let[@inline] append_iter self i = i (add_char self) let[@inline] append_seq self seq = Seq.iter (add_char self) seq +let[@inline] to_slice self = CCByte_slice.create ~len:self.len self.bs let fold_left f acc self = let { bs; len } = self in diff --git a/src/core/CCByte_buffer.mli b/src/core/CCByte_buffer.mli index d3338779..f5daeeb8 100644 --- a/src/core/CCByte_buffer.mli +++ b/src/core/CCByte_buffer.mli @@ -65,6 +65,10 @@ val unsafe_get : t -> int -> char val set : t -> int -> char -> unit val unsafe_set : t -> int -> char -> unit +val to_slice : t -> CCByte_slice.t +(** [to_slice buf] returns a slice of the current content. + The slice shares the same byte array as [buf] (until [buf] is resized). *) + val contents : t -> string (** Copy the internal data to a string. Allocates. *)