perf(util): more inlining

This commit is contained in:
Simon Cruanes 2022-08-14 22:32:51 -04:00
parent 23e70a192a
commit 6f42c060f4
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 12 additions and 11 deletions

View file

@ -15,8 +15,8 @@ let hash_int_ n =
(h := Int64.(mul !h fnv_prime)); (h := Int64.(mul !h fnv_prime));
h := Int64.(logxor !h (of_int ((n lsr (k * 8)) land 0xff))) h := Int64.(logxor !h (of_int ((n lsr (k * 8)) land 0xff)))
done; done;
(* truncate back to int and remove sign *)
Int64.to_int !h land max_int Int64.to_int !h land max_int
(* truncate back to int and remove sign *)
let combine2 a b = let combine2 a b =
let h = ref fnv_offset_basis in let h = ref fnv_offset_basis in
@ -60,20 +60,21 @@ let combine4 a b c d =
done; done;
Int64.to_int !h land max_int Int64.to_int !h land max_int
let pair f g (x, y) = combine2 (f x) (g y) let[@inline] pair f g (x, y) = combine2 (f x) (g y)
let opt f = function let opt f = function
| None -> 42 | None -> 42
| Some x -> combine2 43 (f x) | Some x -> combine2 43 (f x)
let int = hash_int_ let[@inline] int x = hash_int_ x
let h_true_ = hash_int_ 1
let h_false_ = hash_int_ 0
let bool b = let[@inline] bool b =
hash_int_ if b then
(if b then h_true_
1 else
else h_false_
2)
let list f l = List.fold_left (combine f) 0x42 l let list f l = List.fold_left (combine f) 0x42 l
let array f = Array.fold_left (combine f) 0x43 let array f = Array.fold_left (combine f) 0x43

View file

@ -1,6 +1,6 @@
(** {1 Logging functions, real version} *) (** {1 Logging functions, real version} *)
let enabled = true (* NOTE: change here for 0-overhead *) let enabled = true (* NOTE: change here for 0-overhead? *)
let debug_level_ = ref 0 let debug_level_ = ref 0
let set_debug l = debug_level_ := l let set_debug l = debug_level_ := l
@ -9,7 +9,7 @@ let debug_fmt_ = ref Format.err_formatter
let set_debug_out f = debug_fmt_ := f let set_debug_out f = debug_fmt_ := f
(* does the printing, inconditionally *) (* does the printing, inconditionally *)
let debug_real_ l k = let[@inline never] debug_real_ l k =
k (fun fmt -> k (fun fmt ->
Format.fprintf !debug_fmt_ "@[<2>@{<Blue>[%d|%.3f]@}@ " l (Sys.time ()); Format.fprintf !debug_fmt_ "@[<2>@{<Blue>[%d|%.3f]@}@ " l (Sys.time ());
Format.kfprintf (fun fmt -> Format.fprintf fmt "@]@.") !debug_fmt_ fmt) Format.kfprintf (fun fmt -> Format.fprintf fmt "@]@.") !debug_fmt_ fmt)