mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 03:05:31 -05:00
perf: small changes in Event
This commit is contained in:
parent
1eb26e5091
commit
9c57dad3f1
1 changed files with 14 additions and 7 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue