Skip to content

Commit

Permalink
Use exception patterns in pattern matching instead of match try
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterDA committed Oct 14, 2021
1 parent fd419ee commit 40b2a9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/unix/lwt_engine.ml
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ let bad_fd fd =
true

let invoke_actions fd map =
match try Some(Fd_map.find fd map) with Not_found -> None with
| Some actions -> Lwt_sequence.iter_l (fun f -> f ()) actions
| None -> ()
match Fd_map.find fd map with
| exception Not_found -> ()
| actions -> Lwt_sequence.iter_l (fun f -> f ()) actions

class virtual select_or_poll_based = object
inherit abstract
Expand Down
22 changes: 9 additions & 13 deletions src/unix/lwt_unix.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,12 @@ let set_notification id f =
Notifiers.replace notifiers id { notifier with notify_handler = f }

let call_notification id =
match try Some(Notifiers.find notifiers id) with Not_found -> None with
| Some notifier ->
match Notifiers.find notifiers id with
| exception Not_found -> ()
| notifier ->
if notifier.notify_once then
stop_notification id;
notifier.notify_handler ()
| None ->
()

(* +-----------------------------------------------------------------+
| Sleepers |
Expand Down Expand Up @@ -1360,11 +1359,9 @@ let readdir_n handle count =
if i = count then
Lwt.return array
else
match try array.(i) <- Unix.readdir handle; true with End_of_file -> false with
| true ->
fill (i + 1)
| false ->
Lwt.return (Array.sub array 0 i)
match array.(i) <- Unix.readdir handle with
| exception End_of_file -> Lwt.return (Array.sub array 0 i)
| () -> fill (i + 1)
in
fill 0
else
Expand Down Expand Up @@ -2299,11 +2296,10 @@ let disable_signal_handler id =
end

let reinstall_signal_handler signum =
match try Some (Signal_map.find signum !signals) with Not_found -> None with
| Some (notification, _) ->
match Signal_map.find signum !signals with
| exception Not_found -> ()
| notification, _ ->
set_signal signum notification
| None ->
()

(* +-----------------------------------------------------------------+
| Processes |
Expand Down

0 comments on commit 40b2a9a

Please sign in to comment.