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,14 +6,21 @@ 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 =
if Vec.is_empty self.h then
[]
else (
let l = ref [] in let l = ref [] in
Vec.iter self.h ~f:(fun h -> l := h x :: !l); Vec.iter self.h ~f:(fun h -> l := h x :: !l);
!l !l
)
let emit_iter self x ~f = let emit_iter self x ~f =
if not (Vec.is_empty self.h) then
Vec.iter self.h ~f:(fun h -> Vec.iter self.h ~f:(fun h ->
let y = h x in let y = h x in
f y) f y)