Skip to content

Commit

Permalink
ezxenstore: avoid copies when converting to and from uuids
Browse files Browse the repository at this point in the history
Signed-off-by: Pau Ruiz Safont <[email protected]>
  • Loading branch information
psafont committed Oct 8, 2024
1 parent 9d0949d commit 89e7cd1
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions ocaml/libs/ezxenstore/watch/ez_xenctrl_uuid.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,14 @@
* GNU Lesser General Public License for more details.
*)

let bytes_of_handle h =
let s = Bytes.make 16 '\000' in
for i = 0 to 15 do
Bytes.set s i (char_of_int h.(i))
done ;
s

let uuid_of_handle h =
let h' = bytes_of_handle h |> Bytes.to_string in
let h' = String.init 16 (fun i -> char_of_int h.(i)) in
match Uuidm.of_binary_string h' with
| Some x ->
x
| None ->
failwith (Printf.sprintf "VM handle '%s' is an invalid uuid" h')

let handle_of_uuid u =
let s = Uuidm.to_bytes u in
let h = Array.make 16 0 in
for i = 0 to 15 do
h.(i) <- int_of_char s.[i]
done ;
h
let s = Uuidm.to_binary_string u in
Array.init 16 (fun i -> int_of_char s.[i])

0 comments on commit 89e7cd1

Please sign in to comment.