diff --git a/src/irmin-pack/io/atomic_write.ml b/src/irmin-pack/io/atomic_write.ml index fd613893f4..a430955fe8 100644 --- a/src/irmin-pack/io/atomic_write.ml +++ b/src/irmin-pack/io/atomic_write.ml @@ -1,45 +1,19 @@ open Import include Irmin_pack.Atomic_write -module UnsafeTbl (K : Irmin.Type.S) = Hashtbl.Make (struct - type t = K.t [@@deriving irmin ~short_hash ~equal] - - let hash = short_hash ?seed:None -end) - -(** Safe but might be incredibly slow. *) module Table (K : Irmin.Type.S) = struct - module Unsafe = UnsafeTbl (K) - - type 'a t = { lock : Eio.Mutex.t; data : 'a Unsafe.t } - - let create n = - let lock = Eio.Mutex.create () in - let data = Unsafe.create n in - { lock; data } - - let add { lock; data } k v = - Eio.Mutex.use_rw ~protect:true lock @@ fun () -> Unsafe.add data k v - - let mem { lock; data } k = - Eio.Mutex.use_rw ~protect:true lock @@ fun () -> Unsafe.mem data k - - let find_opt { lock; data } k = - Eio.Mutex.use_rw ~protect:true lock @@ fun () -> Unsafe.find_opt data k - - let find t k = match find_opt t k with Some v -> v | None -> raise Not_found + module K = (struct + include K - let replace { lock; data } k v = - Eio.Mutex.use_rw ~protect:true lock @@ fun () -> Unsafe.replace data k v + type t = K.t [@@deriving irmin ~short_hash ~equal] - let remove { lock; data } k = - Eio.Mutex.use_rw ~protect:true lock @@ fun () -> Unsafe.remove data k + let hash = short_hash ?seed:None + let equal = Irmin.Type.(unstage (equal K.t)) + end) - let reset { lock; data } = - Eio.Mutex.use_rw ~protect:true lock @@ fun () -> Unsafe.reset data + include Kcas_data.Hashtbl - let fold f { lock; data } init = - Eio.Mutex.use_rw ~protect:true lock @@ fun () -> Unsafe.fold f data init + let create min_buckets = create ~hashed_type:(module K) ~min_buckets () end module Make_persistent (Io : Io_intf.S) (K : Irmin.Type.S) (V : Value.S) = @@ -53,8 +27,8 @@ struct type watch = W.watch type t = { - index : int63 Tbl.t; - cache : V.t Tbl.t; + index : (K.t, int63) Tbl.t; + cache : (K.t, V.t) Tbl.t; block : Io.t; mutable block_size : int63; w : W.t; diff --git a/src/irmin-pack/io/pack_store.ml b/src/irmin-pack/io/pack_store.ml index 8563a87ae4..acfa41d3fc 100644 --- a/src/irmin-pack/io/pack_store.ml +++ b/src/irmin-pack/io/pack_store.ml @@ -24,37 +24,17 @@ exception Dangling_hash let invalid_read fmt = Fmt.kstr (fun s -> raise (Invalid_read s)) fmt let corrupted_store fmt = Fmt.kstr (fun s -> raise (Corrupted_store s)) fmt -module UnsafeTbl (K : Irmin.Hash.S) = Hashtbl.Make (struct - type t = K.t - - let hash = K.short_hash - let equal = Irmin.Type.(unstage (equal K.t)) -end) - -(** Safe but might be incredibly slow. *) module Table (K : Irmin.Hash.S) = struct - module Unsafe = UnsafeTbl (K) - - type 'a t = { lock : Eio.Mutex.t; data : 'a Unsafe.t } - - let create n = - let lock = Eio.Mutex.create () in - let data = Unsafe.create n in - { lock; data } - - let add { lock; data } k v = - Eio.Mutex.use_rw ~protect:true lock @@ fun () -> Unsafe.add data k v - - let mem { lock; data } k = - Eio.Mutex.use_rw ~protect:true lock @@ fun () -> Unsafe.mem data k + module K = (struct + include K - let find_opt { lock; data } k = - Eio.Mutex.use_rw ~protect:true lock @@ fun () -> Unsafe.find_opt data k + let hash = short_hash + let equal = Irmin.Type.(unstage (equal K.t)) + end) - let find t k = match find_opt t k with Some v -> v | None -> raise Not_found + include Kcas_data.Hashtbl - let clear { lock; data } = - Eio.Mutex.use_rw ~protect:true lock @@ fun () -> Unsafe.clear data + let create min_buckets = create ~hashed_type:(module K) ~min_buckets () end module Make_without_close_checks @@ -86,7 +66,7 @@ struct type 'a t = { lru : Lru.t; - staging : Val.t Tbl.t; + staging : (Hash.t, Val.t) Tbl.t; indexing_strategy : Irmin_pack.Indexing_strategy.t; fm : Fm.t; dict : Dict.t;