Skip to content

Commit 248018c

Browse files
bhartnettchirag-parmar
authored andcommitted
Make encodeLeaf a func and store hashKeys in encodeBranch.
1 parent 8581f94 commit 248018c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

execution_chain/db/aristo/aristo_compute.nim

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ template appendLeaf(w: var RlpWriter, pfx: NibblesBuf, leafData: Account | UInt2
117117
w.wrapEncoding(1)
118118
w.append(leafData)
119119

120-
template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: Account | UInt256): HashKey =
120+
func encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: Account | UInt256): HashKey =
121121
w.clear()
122122
w.tracker.appendLeaf(pfx, leafData)
123123

@@ -132,24 +132,28 @@ template encodeLeaf(w: var AristoTrieWriter, pfx: NibblesBuf, leafData: Account
132132
let buf = w.hashWriter.finish()
133133
buf.to(HashKey)
134134

135-
template appendBranch(w: var RlpWriter, vtx: VertexRef, subKeyForN: untyped) =
135+
template appendBranch(w: var RlpWriter, vtx: VertexRef, hashKeys: array[16, HashKey]) =
136136
w.startList(17)
137-
for (n {.inject.}, subvid {.inject.}) in vtx.allPairs():
138-
w.append(subKeyForN)
137+
for key in hashKeys:
138+
w.append(key)
139139
w.append EmptyBlob
140140

141141
template encodeBranch(w: var AristoTrieWriter, rvtx: VertexRef, subKeyForN: untyped): HashKey =
142+
var hashKeys: array[16, HashKey]
143+
for (n {.inject.}, subvid {.inject.}) in vtx.allPairs():
144+
hashKeys[n] = subKeyForN
145+
142146
w.clear()
143-
w.tracker.appendBranch(vtx, subKeyForN)
147+
w.tracker.appendBranch(vtx, hashKeys)
144148

145149
if w.tracker.totalLength < 32:
146150
w.twoPassWriter.reInit(w.tracker)
147-
w.twoPassWriter.appendBranch(vtx, subKeyForN)
151+
w.twoPassWriter.appendBranch(vtx, hashKeys)
148152
let buf = HashKey.fromBytes(w.twoPassWriter.finish)
149153
buf.value
150154
else:
151155
w.hashWriter.reInit(w.tracker)
152-
w.hashWriter.appendBranch(vtx, subKeyForN)
156+
w.hashWriter.appendBranch(vtx, hashKeys)
153157
let buf = w.hashWriter.finish()
154158
buf.to(HashKey)
155159

0 commit comments

Comments
 (0)