Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Move loop-invariant offset calculation outside loop #35

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions smt.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ func (smt *SparseMerkleTree) updateWithSideNodes(path []byte, value []byte, side
currentData = currentHash
}

// The offset from the bottom of the tree to the start of the side nodes.
// Note: i-offsetOfSideNodes is the index into sideNodes[]
offsetOfSideNodes := smt.depth() - len(sideNodes)

for i := 0; i < smt.depth(); i++ {
sideNode := make([]byte, smt.th.pathSize())

// The offset from the bottom of the tree to the start of the side nodes
// i-offsetOfSideNodes is the index into sideNodes[]
offsetOfSideNodes := smt.depth() - len(sideNodes)

if i-offsetOfSideNodes < 0 || sideNodes[i-offsetOfSideNodes] == nil {
if commonPrefixCount != smt.depth() && commonPrefixCount > smt.depth()-1-i {
// If there are no sidenodes at this height, but the number of
Expand Down