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

View file

@ -1,6 +1,6 @@
(** {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 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
(* does the printing, inconditionally *)
let debug_real_ l k =
let[@inline never] debug_real_ l k =
k (fun fmt ->
Format.fprintf !debug_fmt_ "@[<2>@{<Blue>[%d|%.3f]@}@ " l (Sys.time ());
Format.kfprintf (fun fmt -> Format.fprintf fmt "@]@.") !debug_fmt_ fmt)