Skip to content

Commit

Permalink
Remove unnecessary branch in TrieQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker committed Jul 31, 2022
1 parent 22eeb3e commit f774617
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions ledger/complete/wal/triequeue.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,13 @@ func (q *TrieQueue) Tries() []*trie.MTrie {

tries := make([]*trie.MTrie, q.count)

if q.isFull() {
// If queue is full, tail points to the oldest element.
head := q.tail
if q.tail >= q.count { // Data isn't wrapped around the slice.
head := q.tail - q.count
copy(tries, q.ts[head:q.tail])
} else { // q.tail < q.count, data is wrapped around the slice.
head := q.capacity - q.count + q.tail
n := copy(tries, q.ts[head:])
copy(tries[n:], q.ts[:q.tail])
} else {
if q.tail >= q.count { // Data isn't wrapped around the slice.
head := q.tail - q.count
copy(tries, q.ts[head:q.tail])
} else { // q.tail < q.count, data is wrapped around the slice.
// This branch isn't used until TrieQueue supports Pop (removing oldest element).
// At this time, there is no reason to implement Pop, so this branch is here to prevent future bug.
head := q.capacity - q.count + q.tail
n := copy(tries, q.ts[head:])
copy(tries[n:], q.ts[:q.tail])
}
}

return tries
Expand Down

0 comments on commit f774617

Please sign in to comment.