diff --git a/ocaml/xapi/xapi_event.ml b/ocaml/xapi/xapi_event.ml index 8c7432106ab..19fb2b0199b 100644 --- a/ocaml/xapi/xapi_event.ml +++ b/ocaml/xapi/xapi_event.ml @@ -49,6 +49,10 @@ module Token = struct Printf.sprintf "%020Ld,%020Ld" last last_t end +let is_lowercase_char c = Char.equal (Char.lowercase_ascii c) c + +let is_lowercase str = String.for_all is_lowercase_char str + module Subscription = struct type t = Class of string | Object of string * string | All @@ -67,11 +71,9 @@ module Subscription = struct (Api_errors.event_subscription_parse_failure, [x]) ) - let any = List.fold_left (fun acc x -> acc || x) false - (** [table_matches subs tbl]: true if at least one subscription from [subs] would select some events from [tbl] *) let table_matches subs tbl = - let tbl = String.lowercase_ascii tbl in + let tbl = if is_lowercase tbl then tbl else String.lowercase_ascii tbl in let matches = function | All -> true @@ -80,11 +82,11 @@ module Subscription = struct | Object (x, _) -> x = tbl in - any (List.map matches subs) + List.exists matches subs (** [event_matches subs ev]: true if at least one subscription from [subs] selects for specified class and object *) let object_matches subs ty _ref = - let tbl = String.lowercase_ascii ty in + let tbl = if is_lowercase ty then ty else String.lowercase_ascii ty in let matches = function | All -> true @@ -93,7 +95,7 @@ module Subscription = struct | Object (x, y) -> x = tbl && y = _ref in - any (List.map matches subs) + List.exists matches subs (** [event_matches subs ev]: true if at least one subscription from [subs] selects for event [ev] *) let event_matches subs ev = object_matches subs ev.ty ev.reference @@ -540,11 +542,7 @@ let from_inner __context session subs from from_t deadline = Db_cache_types.Table.fold_over_recent !last_generation (fun objref {Db_cache_types.Stat.created; modified; deleted} _ (creates, mods, deletes, last) -> - if - Subscription.object_matches subs - (String.lowercase_ascii table) - objref - then + if Subscription.object_matches subs table objref then let last = max last (max modified deleted) in (* mtime guaranteed to always be larger than ctime *) ( ( if created > !last_generation then @@ -574,11 +572,7 @@ let from_inner __context session subs from from_t deadline = Db_cache_types.Table.fold_over_deleted !last_generation (fun objref {Db_cache_types.Stat.created; modified; deleted} (creates, mods, deletes, last) -> - if - Subscription.object_matches subs - (String.lowercase_ascii table) - objref - then + if Subscription.object_matches subs table objref then let last = max last (max modified deleted) in (* mtime guaranteed to always be larger than ctime *) if created > !last_generation then