perf: small changes in Event

This commit is contained in:
Simon Cruanes 2022-08-21 22:56:38 -04:00
parent 1eb26e5091
commit 9c57dad3f1
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -6,17 +6,24 @@ let nop_handler_ _ = assert false
module Emitter = struct module Emitter = struct
type nonrec ('a, 'b) t = ('a, 'b) t type nonrec ('a, 'b) t = ('a, 'b) t
let emit (self : (_, unit) t) x = Vec.iter self.h ~f:(fun h -> h x) let emit (self : (_, unit) t) x =
if not (Vec.is_empty self.h) then
(Vec.iter [@inlined]) self.h ~f:(fun h -> h x)
let emit_collect (self : _ t) x : _ list = let emit_collect (self : _ t) x : _ list =
let l = ref [] in if Vec.is_empty self.h then
Vec.iter self.h ~f:(fun h -> l := h x :: !l); []
!l else (
let l = ref [] in
Vec.iter self.h ~f:(fun h -> l := h x :: !l);
!l
)
let emit_iter self x ~f = let emit_iter self x ~f =
Vec.iter self.h ~f:(fun h -> if not (Vec.is_empty self.h) then
let y = h x in Vec.iter self.h ~f:(fun h ->
f y) let y = h x in
f y)
let create () : _ t = { h = Vec.make 3 nop_handler_ } let create () : _ t = { h = Vec.make 3 nop_handler_ }
end end