Skip to content

Commit 430fdbc

Browse files
committed
irmin-tezos: unroll allocation hotspot
1 parent 289249c commit 430fdbc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/irmin-tezos/schema.ml

+10-1
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,17 @@ struct
103103
let entries_t : entry list Irmin.Type.t =
104104
Irmin.Type.(list ~len:`Int64 entry_t)
105105

106+
let pre_hash_entry = Irmin.Type.(unstage (pre_hash entry_t))
106107
let pre_hash_entries = Irmin.Type.(unstage (pre_hash entries_t))
107-
let pre_hash t = M.list t |> pre_hash_entries
108+
let encode_bin_int64 = Irmin.Type.(unstage (pre_hash int64))
109+
110+
let pre_hash t f =
111+
match M.length t with
112+
| 0 -> pre_hash_entries [] f
113+
| 1 ->
114+
encode_bin_int64 1L f;
115+
pre_hash_entry (List.hd (M.list t)) f
116+
| _ -> pre_hash_entries (M.list t) f
108117
end
109118

110119
include M

0 commit comments

Comments
 (0)