From 900da595b174bccac029c2e0d1be5b1947cafe84 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Fri, 9 Dec 2016 16:33:03 -0800 Subject: [PATCH] Core.Std.String.Table Reviewed By: cristianoc Differential Revision: D4232447 fbshipit-source-id: 75e3ecd --- infer/src/backend/mergeCapture.ml | 10 +++++----- infer/src/base/Multilinks.re | 20 ++++++++++---------- infer/src/base/Utils.ml | 3 --- infer/src/base/Utils.mli | 3 --- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/infer/src/backend/mergeCapture.ml b/infer/src/backend/mergeCapture.ml index 9711e37e7..c410fcfa9 100644 --- a/infer/src/backend/mergeCapture.ml +++ b/infer/src/backend/mergeCapture.ml @@ -56,7 +56,7 @@ let link_exists s = (* Table mapping directories to multilinks. Used for the hashed directories where attrbute files are stored. *) -let multilinks_dir_table = StringHash.create 16 +let multilinks_dir_table = String.Table.create ~size:16 () (* Add a multilink for attributes to the internal per-directory table. @@ -66,7 +66,7 @@ let add_multilink_attr ~stats src dst = let attr_dir_name = Filename.basename attr_dir in let multilinks = try - StringHash.find multilinks_dir_table attr_dir_name + String.Table.find_exn multilinks_dir_table attr_dir_name with | Not_found -> let multilinks = match Multilinks.read ~dir:attr_dir with @@ -75,7 +75,7 @@ let add_multilink_attr ~stats src dst = multilinks | None -> Multilinks.create () in - StringHash.add multilinks_dir_table attr_dir_name multilinks; + String.Table.set multilinks_dir_table ~key:attr_dir_name ~data:multilinks; multilinks in Multilinks.add multilinks src; stats.files_multilinked <- stats.files_multilinked + 1 @@ -92,11 +92,11 @@ let create_link ~stats src dst = stats.files_linked <- stats.files_linked + 1 let create_multilinks () = - let do_dir dir multilinks = + let do_dir ~key:dir ~data:multilinks = let attributes_dir = Filename.concat (Filename.concat Config.results_dir Config.attributes_dir_name) dir in Multilinks.write multilinks ~dir:attributes_dir in - StringHash.iter do_dir multilinks_dir_table + String.Table.iteri ~f:do_dir multilinks_dir_table (** Create symbolic links recursively from the destination to the source. diff --git a/infer/src/base/Multilinks.re b/infer/src/base/Multilinks.re index eb426216a..17e073b23 100644 --- a/infer/src/base/Multilinks.re +++ b/infer/src/base/Multilinks.re @@ -14,16 +14,16 @@ let module L = Logging; let multilink_file_name = "multilink.txt"; -type t = StringHash.t string; +type t = String.Table.t string; -let add multilinks fname => StringHash.replace multilinks (Filename.basename fname) fname; +let add multilinks fname => String.Table.set multilinks key::(Filename.basename fname) data::fname; -let create () :t => StringHash.create 1; +let create () :t => String.Table.create size::1 (); /* Cache of multilinks files read from disk */ -let multilink_files_cache = StringHash.create 1; +let multilink_files_cache = String.Table.create size::1 (); -let reset_cache () => StringHash.reset multilink_files_cache; +let reset_cache () => String.Table.clear multilink_files_cache; let read dir::dir :option t => { let multilink_fname = Filename.concat dir multilink_file_name; @@ -31,8 +31,8 @@ let read dir::dir :option t => { | None => None | Some lines => let links = create (); - IList.iter (fun line => StringHash.add links (Filename.basename line) line) lines; - StringHash.add multilink_files_cache dir links; + IList.iter (fun line => String.Table.set links key::(Filename.basename line) data::line) lines; + String.Table.set multilink_files_cache key::dir data::links; Some links } }; @@ -41,12 +41,12 @@ let read dir::dir :option t => { let write multilinks dir::dir => { let fname = Filename.concat dir multilink_file_name; let outc = open_out fname; - StringHash.iter (fun _ src => output_string outc (src ^ "\n")) multilinks; + String.Table.iteri f::(fun key::_ data::src => output_string outc (src ^ "\n")) multilinks; close_out outc }; let lookup dir::dir => - try (Some (StringHash.find multilink_files_cache dir)) { + try (Some (String.Table.find_exn multilink_files_cache dir)) { | Not_found => read dir::dir }; @@ -60,7 +60,7 @@ let resolve fname => { switch (lookup dir::dir) { | None => fname | Some links => - try (DB.filename_from_string (StringHash.find links base)) { + try (DB.filename_from_string (String.Table.find_exn links base)) { | Not_found => fname } } diff --git a/infer/src/base/Utils.ml b/infer/src/base/Utils.ml index 02470e15a..bbbed1c50 100644 --- a/infer/src/base/Utils.ml +++ b/infer/src/base/Utils.ml @@ -87,9 +87,6 @@ let int_of_bool b = if b then 1 else 0 (** Set of integers *) module IntSet = Set.Make(Int) -(** Hash table over strings *) -module StringHash = Hashtbl.Make (String) - (** Maps from integers *) module IntMap = Map.Make (Int) diff --git a/infer/src/base/Utils.mli b/infer/src/base/Utils.mli index 3d6e4d749..43ab61b89 100644 --- a/infer/src/base/Utils.mli +++ b/infer/src/base/Utils.mli @@ -75,9 +75,6 @@ val int_of_bool : bool -> int (** Set of integers *) module IntSet : Set.S with type elt = int -(** Hash table over strings *) -module StringHash : Hashtbl.S with type key = string - (** Maps from integers *) module IntMap : Map.S with type key = int