Switch from maps to tables for variables
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
43b15bf944
commit
843792ad5d
|
@ -37,6 +37,24 @@ module Make(H : Hashable.S) = struct
|
||||||
fold t ~init ~f:(fun ~key ~data acc -> f key data acc)
|
fold t ~init ~f:(fun ~key ~data acc -> f key data acc)
|
||||||
let fold t ~init ~f = foldi t ~init ~f:(fun _ x -> f x)
|
let fold t ~init ~f = foldi t ~init ~f:(fun _ x -> f x)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let of_list l =
|
||||||
|
let h = create (List.length l) in
|
||||||
|
let rec loop = function
|
||||||
|
| [] -> Result.Ok h
|
||||||
|
| (k, v) :: xs ->
|
||||||
|
begin match find h k with
|
||||||
|
| None -> add h k v; loop xs
|
||||||
|
| Some v' -> Error (k, v', v)
|
||||||
|
end
|
||||||
|
in
|
||||||
|
loop l
|
||||||
|
|
||||||
|
let of_list_exn l =
|
||||||
|
match of_list l with
|
||||||
|
| Result.Ok h -> h
|
||||||
|
| Error (_, _, _) ->
|
||||||
|
Exn.code_error "Hashtbl.of_list_exn duplicate keys" []
|
||||||
end
|
end
|
||||||
|
|
||||||
open MoreLabels.Hashtbl
|
open MoreLabels.Hashtbl
|
||||||
|
|
|
@ -8,4 +8,6 @@ module type S = sig
|
||||||
|
|
||||||
val fold : 'a t -> init:'b -> f:('a -> 'b -> 'b) -> 'b
|
val fold : 'a t -> init:'b -> f:('a -> 'b -> 'b) -> 'b
|
||||||
val foldi : 'a t -> init:'b -> f:(key -> 'a -> 'b -> 'b) -> 'b
|
val foldi : 'a t -> init:'b -> f:(key -> 'a -> 'b -> 'b) -> 'b
|
||||||
|
|
||||||
|
val of_list_exn : (key * 'a) list -> 'a t
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,8 @@ let compare a b = Ordering.of_int (String.compare a b)
|
||||||
module T = struct
|
module T = struct
|
||||||
type t = StringLabels.t
|
type t = StringLabels.t
|
||||||
let compare = compare
|
let compare = compare
|
||||||
|
let equal (x : t) (y : t) = x = y
|
||||||
|
let hash (s : t) = Hashtbl.hash s
|
||||||
end
|
end
|
||||||
|
|
||||||
let capitalize = capitalize_ascii
|
let capitalize = capitalize_ascii
|
||||||
|
@ -201,6 +203,7 @@ let maybe_quoted s =
|
||||||
|
|
||||||
module Set = Set.Make(T)
|
module Set = Set.Make(T)
|
||||||
module Map = Map.Make(T)
|
module Map = Map.Make(T)
|
||||||
|
module Table = Hashtbl.Make(T)
|
||||||
|
|
||||||
let enumerate_gen s =
|
let enumerate_gen s =
|
||||||
let s = " " ^ s ^ " " in
|
let s = " " ^ s ^ " " in
|
||||||
|
|
|
@ -53,3 +53,4 @@ val enumerate_or : string list -> string
|
||||||
|
|
||||||
module Set : Set.S with type elt = t
|
module Set : Set.S with type elt = t
|
||||||
module Map : Map.S with type key = t
|
module Map : Map.S with type key = t
|
||||||
|
module Table : Hashtbl.S with type key = t
|
||||||
|
|
|
@ -122,7 +122,7 @@ end = struct
|
||||||
| Renamed_in of Syntax.Version.t * string
|
| Renamed_in of Syntax.Version.t * string
|
||||||
|
|
||||||
module Map = struct
|
module Map = struct
|
||||||
type nonrec 'a t = 'a t String.Map.t
|
type nonrec 'a t = 'a t String.Table.t
|
||||||
|
|
||||||
let values v = Nothing (Kind.Values v)
|
let values v = Nothing (Kind.Values v)
|
||||||
let renamed_in ~new_name ~version = Renamed_in (version, new_name)
|
let renamed_in ~new_name ~version = Renamed_in (version, new_name)
|
||||||
|
@ -161,7 +161,7 @@ end = struct
|
||||||
|
|
||||||
; "path-no-dep", deleted_in ~version:(1, 0) Path_no_dep
|
; "path-no-dep", deleted_in ~version:(1, 0) Path_no_dep
|
||||||
]
|
]
|
||||||
|> String.Map.of_list_exn
|
|> String.Table.of_list_exn
|
||||||
|
|
||||||
let create_vars ~(context : Context.t) ~cxx_flags =
|
let create_vars ~(context : Context.t) ~cxx_flags =
|
||||||
let ocamlopt =
|
let ocamlopt =
|
||||||
|
@ -226,9 +226,9 @@ end = struct
|
||||||
; vars
|
; vars
|
||||||
]
|
]
|
||||||
|> List.concat
|
|> List.concat
|
||||||
|> String.Map.of_list_exn
|
|> String.Table.of_list_exn
|
||||||
|
|
||||||
let static_vars = String.Map.of_list_exn static_vars
|
let static_vars = String.Table.of_list_exn static_vars
|
||||||
|
|
||||||
let rec expand t ~syntax_version ~var =
|
let rec expand t ~syntax_version ~var =
|
||||||
let name =
|
let name =
|
||||||
|
@ -236,7 +236,7 @@ end = struct
|
||||||
| Single v -> v
|
| Single v -> v
|
||||||
| Pair (v, _) -> v
|
| Pair (v, _) -> v
|
||||||
in
|
in
|
||||||
Option.bind (String.Map.find t name) ~f:(function
|
Option.bind (String.Table.find t name) ~f:(function
|
||||||
| Nothing v -> Some v
|
| Nothing v -> Some v
|
||||||
| Since (v, min_version) ->
|
| Since (v, min_version) ->
|
||||||
if syntax_version >= min_version then
|
if syntax_version >= min_version then
|
||||||
|
|
Loading…
Reference in New Issue