Skip to content

Commit

Permalink
Merge pull request #2 from ef-ds/simplify-pop-logic
Browse files Browse the repository at this point in the history
Simplify pop logic
  • Loading branch information
christianrpetrin authored Jan 5, 2019
2 parents e9faa24 + a7add05 commit 2b8ceb7
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@ func (s *Stack) Pop() (interface{}, bool) {
v := *vp
*vp = nil // Avoid memory leaks
s.tail.v = s.tail.v[:tp]
switch {
case tp > 0:
// There's space before tp.
default:
// Leave the slice unused as spare.
if tp <= 0 {
// Move to the previous slice as all elements
// in the current one were removed.
s.tail = s.tail.p
}
return v, true
Expand Down

0 comments on commit 2b8ceb7

Please sign in to comment.