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

Commit

Permalink
Move loop-invariant offset calculation outside loop. (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerjohn authored Jun 8, 2021
1 parent 54602cb commit 8dd3dfe
Showing 1 changed file with 4 additions and 4 deletions.
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

0 comments on commit 8dd3dfe

Please sign in to comment.