mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
daemon, generator: Use power of 2 for initial size of Hashtbl.create
Before 2011 it was recommended to use a prime number for the initial size. In 2011 the OCaml hash table was reimplemented using a hash function based on Murmur 3. Hashtbl.create now adjusts the initial size to the next power of 2 (minimum 16). So replace obsolete 'Hashtbl.create 13' with 'Hashtbl.create 16'.
This commit is contained in:
@@ -35,7 +35,7 @@ let setfiles_has_option =
|
||||
let _, _, err = commandr "setfiles" [opt] in
|
||||
String.find err err_msg = -1
|
||||
in
|
||||
let h = Hashtbl.create 13 in
|
||||
let h = Hashtbl.create 16 in
|
||||
fun flag ->
|
||||
try Hashtbl.find h flag
|
||||
with
|
||||
|
||||
@@ -44,7 +44,7 @@ let create ?(version = 1) ?(batch_size = 100) name lookup_fn =
|
||||
let filename = sprintf "generator/.%s.data.version.%d" name version in
|
||||
let memo =
|
||||
try with_open_in filename input_value
|
||||
with _ -> Hashtbl.create 13 in
|
||||
with _ -> Hashtbl.create 16 in
|
||||
{
|
||||
memo; filename; lookup_fn; batch_size; unsaved_count = 0;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ let optgroups_retired = [
|
||||
|
||||
(* Create list of optional groups. *)
|
||||
let optgroups =
|
||||
let h = Hashtbl.create 13 in
|
||||
let h = Hashtbl.create 16 in
|
||||
List.iter (
|
||||
function
|
||||
| { optional = Some group } as fn ->
|
||||
|
||||
@@ -32,7 +32,7 @@ let lines = ref 0
|
||||
|
||||
(* Name of each file generated. *)
|
||||
let files = ref []
|
||||
let fileshash = Hashtbl.create 13
|
||||
let fileshash = Hashtbl.create 16
|
||||
|
||||
(* Print-to-current-output function, used everywhere. It has
|
||||
* printf-like semantics.
|
||||
|
||||
@@ -64,7 +64,7 @@ let rec generate_c_api_tests () =
|
||||
pr " size_t i;\n";
|
||||
pr " const char *no_tests[] = {\n";
|
||||
|
||||
let hash : (string, bool) Hashtbl.t = Hashtbl.create 13 in
|
||||
let hash : (string, bool) Hashtbl.t = Hashtbl.create 16 in
|
||||
List.iter (
|
||||
fun { tests } ->
|
||||
let seqs = List.filter_map (
|
||||
|
||||
@@ -109,7 +109,7 @@ let rstructs_used_by functions =
|
||||
| RStructListOnly, RStructListOnly -> RStructListOnly
|
||||
in
|
||||
|
||||
let h = Hashtbl.create 13 in
|
||||
let h = Hashtbl.create 16 in
|
||||
|
||||
(* if elem->oldv exists, update entry using ||| operator,
|
||||
* else just add elem->newv to the hash
|
||||
|
||||
Reference in New Issue
Block a user