From f7746174e19d884226aefa82dcda639c255b8a7c Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Sun, 31 Jul 2022 17:08:40 -0500 Subject: [PATCH] Remove unnecessary branch in TrieQueue --- ledger/complete/wal/triequeue.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/ledger/complete/wal/triequeue.go b/ledger/complete/wal/triequeue.go index c66d8c231a9..dd63467f48d 100644 --- a/ledger/complete/wal/triequeue.go +++ b/ledger/complete/wal/triequeue.go @@ -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