tools/oxenstored: Backport find_opt/update from 4.06

We are currently on OCaml 4.02 as minimum version.  To make the followup
optimizations compile backport these functions from OCaml 4.06.

This implementation is less efficient than the one in the 4.06 standard
library which has access to the internals of the Map.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
This commit is contained in:
Edwin Török authored and Andrew Cooper committed 2021-01-22 18:01:34 +00:00
1 parent 5e115dcf76
commit faf02c345e
2 files changed
+21

No files matched your search

+19
View File
@@ -50,6 +50,25 @@ module Filename = struct
cmd :: args |> List.map quote |> String.concat " "
end
module Map = struct
module Make(Ord: Map.OrderedType) = struct
include Map.Make(Ord)
let find_opt k t = try Some (find k t) with Not_found -> None
let update k f t =
let r = find_opt k t in
let r' = f r in
match r, r' with
| None, None -> t
| Some _, None -> remove k t
| Some r, Some r' when r == r' -> t
| _, Some r' -> add k r' t
end
end
module String = struct include String
let of_char c = String.make 1 c
+2
View File
@@ -13,6 +13,8 @@
* GNU Lesser General Public License for more details.
*)
open Stdext
module Node =
struct
type ('a,'b) t = {
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.