Skip to content

Commit 259fb4e

Browse files
Andrii Sultanovcontificate
authored andcommitted
Refactor: Move to default optional parameters when they were reimplemented by hand
Signed-off-by: Andrii Sultanov <andrii.sultanov@cloud.com>
1 parent a91635e commit 259fb4e

File tree

7 files changed

+19
-29
lines changed

7 files changed

+19
-29
lines changed

ocaml/libs/tracing/tracing.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ module TracerProvider = struct
519519
get_tracer_providers_unlocked
520520

521521
let set ?enabled ?attributes ?endpoints ~uuid () =
522-
let update_provider (provider : t) enabled attributes endpoints =
523-
let enabled = Option.value ~default:provider.enabled enabled in
522+
let update_provider (provider : t) ?(enabled = provider.enabled) attributes
523+
endpoints =
524524
let attributes : string Attributes.t =
525525
Option.fold ~none:provider.attributes ~some:Attributes.of_list
526526
attributes
@@ -537,7 +537,7 @@ module TracerProvider = struct
537537
let provider =
538538
match Hashtbl.find_opt tracer_providers uuid with
539539
| Some (provider : t) ->
540-
update_provider provider enabled attributes endpoints
540+
update_provider provider ?enabled attributes endpoints
541541
| None ->
542542
fail "The TracerProvider : %s does not exist" uuid
543543
in

ocaml/libs/vhd/vhd_format/f.ml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,9 @@ module Footer = struct
397397
let create ?(features = []) ~data_offset ?(time_stamp = 0l)
398398
?(creator_application = default_creator_application)
399399
?(creator_version = default_creator_version)
400-
?(creator_host_os = Host_OS.Other 0l) ~current_size ?original_size
401-
~disk_type ?(uid = Uuidm.v `V4) ?(saved_state = false) () =
402-
let original_size =
403-
match original_size with None -> current_size | Some x -> x
404-
in
400+
?(creator_host_os = Host_OS.Other 0l) ~current_size
401+
?(original_size = current_size) ~disk_type ?(uid = Uuidm.v `V4)
402+
?(saved_state = false) () =
405403
let geometry = Geometry.of_sectors Int64.(current_size lsr sector_shift) in
406404
let checksum = 0l in
407405
{

ocaml/xapi-idl/lib/typeCombinators.ml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,28 @@ type dict = (string * string) list [@@deriving rpcty]
1616

1717
let option ?name ?(description = []) d =
1818
let open Rpc.Types in
19-
let name =
20-
Option.fold ~none:(Printf.sprintf "%s option" d.name) ~some:Fun.id name
21-
in
19+
let name = Option.value ~default:(Printf.sprintf "%s option" d.name) name in
2220
{name; description; ty= Option d.ty}
2321

2422
let list ?name ?(description = []) d =
2523
let open Rpc.Types in
26-
let name =
27-
Option.fold ~none:(Printf.sprintf "list of %ss" d.name) ~some:Fun.id name
28-
in
24+
let name = Option.value ~default:(Printf.sprintf "list of %ss" d.name) name in
2925
{name; description; ty= List d.ty}
3026

3127
let pair ?name ?(description = []) (p0, p2) =
3228
let open Rpc.Types in
3329
let name =
34-
Option.fold
35-
~none:(Printf.sprintf "pair of %s and %s" p0.name p2.name)
36-
~some:Fun.id name
30+
Option.value
31+
~default:(Printf.sprintf "pair of %s and %s" p0.name p2.name)
32+
name
3733
in
3834
{name; description; ty= Tuple (p0.ty, p2.ty)}
3935

4036
let triple ?name ?(description = []) (p1, p2, p3) =
4137
let open Rpc.Types in
4238
let name =
43-
Option.fold
44-
~none:(Printf.sprintf "triple of %s, %s and %s" p1.name p2.name p3.name)
45-
~some:Fun.id name
39+
Option.value
40+
~default:(Printf.sprintf "triple of %s, %s and %s" p1.name p2.name p3.name)
41+
name
4642
in
4743
{name; description; ty= Tuple3 (p1.ty, p2.ty, p3.ty)}

ocaml/xapi/cert_distrib.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,12 @@ module WireProtocol = struct
9494
let certificate_file_of_pair (filename, content) = {filename; content}
9595
end
9696

97-
let raise_internal ?e ?details msg : 'a =
97+
let raise_internal ?e ?(details = "") msg : 'a =
9898
let e =
9999
Option.fold ~none:""
100100
~some:(fun e -> e |> Printexc.to_string |> Printf.sprintf "exception: %s")
101101
e
102102
in
103-
let details = Option.value ~default:"" details in
104103
[msg; details; e] |> String.concat ". " |> D.error "%s" ;
105104
raise Api_errors.(Server_error (internal_error, [msg]))
106105

ocaml/xapi/workload_balancing.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,9 @@ let wlb_request ~__context ~host ~port ~auth ~meth ~params ~handler ~enable_log
351351
| Unix.Unix_error (Unix.ECONNREFUSED, _, _) ->
352352
raise_connection_refused ()
353353

354-
let perform_wlb_request ?auth ?url ?enable_log ~meth ~params ~handle_response
355-
~__context () =
354+
let perform_wlb_request ?auth ?url ?(enable_log = true) ~meth ~params
355+
~handle_response ~__context () =
356356
(* now assumes naming policy of xml repsonses is uniform Envelope->Body-> <x>Response-> <x>Result where <x> is method name *)
357-
let enable_log = match enable_log with Some b -> b | None -> true in
358357
let host, port =
359358
match url with
360359
| Some u ->

ocaml/xapi/xapi_mgmt_iface.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ let next_server_mode ~mgmt_enabled =
184184

185185
let mgmt_is_enabled () = Server.current_mode () = Any
186186

187-
let run ~__context ?mgmt_enabled () =
188-
let mgmt_enabled = Option.value ~default:(mgmt_is_enabled ()) mgmt_enabled in
187+
let run ~__context ?(mgmt_enabled = mgmt_is_enabled ()) () =
189188
with_lock management_m (fun () ->
190189
Client_certificate_auth_server.update ~__context ~mgmt_enabled ;
191190
next_server_mode ~mgmt_enabled |> Server.update ~__context ;

ocaml/xenopsd/xc/service.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,8 @@ module PV_Vnc = struct
949949
| None ->
950950
()
951951

952-
let start ?statefile ~xs ?ip domid =
952+
let start ?statefile ~xs ?(ip = "127.0.0.1") domid =
953953
debug "In PV_Vnc.start" ;
954-
let ip = Option.value ~default:"127.0.0.1" ip in
955954
let l =
956955
[
957956
"-x"

0 commit comments

Comments
 (0)