[sledge] Minor exception optimizations

Summary:
When exceptions are used due to the lack of goto, use `raise_notrace`
instead of `raise` to avoid the overhead of populating the backtrace.

Reviewed By: ngorogiannis

Differential Revision: D24630525

fbshipit-source-id: c5051d9c4
master
Josh Berdine 4 years ago committed by Facebook GitHub Bot
parent 7f9afea411
commit 22f17140f0

@ -76,19 +76,21 @@ end) : S with type key = Key.t = struct
let is_empty = M.is_empty let is_empty = M.is_empty
let root_key m = let root_key m =
let exception Found in if M.is_empty m then None
let found = ref None in else
try let exception Found in
M.find_first let found = ref None in
(fun key -> try
found := Some key ; M.find_first
raise Found ) (fun key ->
m found := Some key ;
|> ignore ; raise_notrace Found )
None m
with |> ignore ;
| Found -> !found None
| Not_found -> None with
| Found -> !found
| Not_found -> None
let root_binding m = let root_binding m =
let exception Found in let exception Found in
@ -97,7 +99,7 @@ end) : S with type key = Key.t = struct
M.for_all M.for_all
(fun key data -> (fun key data ->
found := Some (key, data) ; found := Some (key, data) ;
raise Found ) raise_notrace Found )
m m
|> ignore ; |> ignore ;
None None

@ -53,7 +53,7 @@ end) : S with type elt = Elt.t = struct
S.for_all S.for_all
(fun elt -> (fun elt ->
found := Some elt ; found := Some elt ;
raise Found ) raise_notrace Found )
s s
|> ignore ; |> ignore ;
None None

@ -182,7 +182,7 @@ end = struct
String.init (Array.length elts) ~f:(fun i -> String.init (Array.length elts) ~f:(fun i ->
match elts.(i) with match elts.(i) with
| Z c -> Char.of_int_exn (Z.to_int c) | Z c -> Char.of_int_exn (Z.to_int c)
| _ -> raise Not_a_string ) | _ -> raise_notrace Not_a_string )
with with
| s -> Format.fprintf fs "%S" s | s -> Format.fprintf fs "%S" s
| exception (Not_a_string | Z.Overflow | Failure _) -> | exception (Not_a_string | Z.Overflow | Failure _) ->

@ -154,7 +154,7 @@ and pp_record fs elts =
String.init (IArray.length elts) ~f:(fun i -> String.init (IArray.length elts) ~f:(fun i ->
match IArray.get elts i with match IArray.get elts i with
| Integer {data} -> Char.of_int_exn (Z.to_int data) | Integer {data} -> Char.of_int_exn (Z.to_int data)
| _ -> raise (Invalid_argument "not a string") ) | _ -> raise_notrace (Invalid_argument "not a string") )
with with
| s -> Format.fprintf fs "@[<h>%s@]" (String.escaped s) | s -> Format.fprintf fs "@[<h>%s@]" (String.escaped s)
| exception _ -> | exception _ ->

Loading…
Cancel
Save