From ee57e36dfa6879c05ac6717c29f2df5b546e1256 Mon Sep 17 00:00:00 2001 From: wuyunzhou Date: Sat, 13 May 2017 15:41:15 +0800 Subject: [PATCH] container/heap: avoid up() invoke if down() success at heap.Remove() Change-Id: I6c210e0c23ca533e1f303f88ef9dcb629a294a2a Reviewed-on: https://go-review.googlesource.com/43472 Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer --- src/container/heap/heap.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/container/heap/heap.go b/src/container/heap/heap.go index af05261c10a..b2c64276c82 100644 --- a/src/container/heap/heap.go +++ b/src/container/heap/heap.go @@ -72,8 +72,9 @@ func Remove(h Interface, i int) interface{} { n := h.Len() - 1 if n != i { h.Swap(i, n) - down(h, i, n) - up(h, i) + if !down(h, i, n) { + up(h, i) + } } return h.Pop() }