diff --git a/lib/conntest.ml b/lib/conntest.ml index e2c95fc..6c97f76 100644 --- a/lib/conntest.ml +++ b/lib/conntest.ml @@ -132,6 +132,27 @@ module Make done; !acc + let map_rev_shortcircuit f r = + let i = ref 0 in + let len = length r in + let ring_copy = Array.copy r.ring in + while !i < len do + let idx_opt = wrap_reverse_i r !i in + match idx_opt with + | None -> i := len + | Some idx -> + let value_opt = get_previous r !i in + match value_opt with + | None -> ring_copy.(idx) <- None; i := succ !i + | Some x -> + match f x with + | None -> i := len + | Some y -> + ring_copy.(idx) <- Some y; i := succ !i + done; + { r with ring = ring_copy } + + end module Udp_flow = struct @@ -348,6 +369,27 @@ module Make *) Log.debug (fun m -> m "feed_source: packet_index_diff < 0"); let did_set = ref false in + let map_rev_shortcircuit f r = + let i = ref 0 in + let len = Ring.length r in + let ring_copy = Array.copy r.Ring.ring in + while !i < len do + let idx_opt = Ring.wrap_reverse_i r !i in + match idx_opt with + | None -> i := len + | Some idx -> + let value_opt = Ring.get_previous r !i in + match value_opt with + | None -> ring_copy.(idx) <- None; i := succ !i + | Some x -> + match f x with + | None -> i := len + | Some y -> + ring_copy.(idx) <- Some y; i := succ !i + done; + { r with Ring.ring = ring_copy } + + in (*> goto perf; could use something like 'find_map_rev' * which would try the latest packets first - * which should be more often hit