Skip to content

Commit

Permalink
Replace duplicated code with function call (#197)
Browse files Browse the repository at this point in the history
peek performs the same assertions as peekCheckErr.
There is no need to keep this checks in two places.
  • Loading branch information
janisz authored and cristaloleg committed Jan 7, 2020
1 parent 873e1c2 commit 32b9aa9
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions queue/bytes_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,9 @@ func (q *BytesQueue) peekCheckErr(index int) error {
}

func (q *BytesQueue) peek(index int) ([]byte, int, error) {

if q.count == 0 {
return nil, 0, errEmptyQueue
}

if index <= 0 {
return nil, 0, errInvalidIndex
}

if index+headerEntrySize >= len(q.array) {
return nil, 0, errIndexOutOfBounds
err := q.peekCheckErr(index)
if err != nil {
return nil, 0, err
}

blockSize := int(binary.LittleEndian.Uint32(q.array[index : index+headerEntrySize]))
Expand Down

0 comments on commit 32b9aa9

Please sign in to comment.