From 8d4d5b86ef590c8ef461002a1895c3da61ecb8bf Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 16 Dec 2014 23:32:04 -0800 Subject: [PATCH] fix: don't sort the output of Entries() only sort SortedEntries() License: MIT Signed-off-by: Brian Tiger Chow --- exchange/bitswap/wantlist/wantlist.go | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/exchange/bitswap/wantlist/wantlist.go b/exchange/bitswap/wantlist/wantlist.go index 6ef018668..22b2c1c2c 100644 --- a/exchange/bitswap/wantlist/wantlist.go +++ b/exchange/bitswap/wantlist/wantlist.go @@ -63,26 +63,13 @@ func (w *ThreadSafe) Contains(k u.Key) bool { func (w *ThreadSafe) Entries() []*Entry { w.lk.RLock() defer w.lk.RUnlock() - var es entrySlice - for _, e := range w.set { - es = append(es, e) - } - // TODO rename SortedEntries (state that they're sorted so callers know - // they're paying an expense) - sort.Sort(es) - return es + return w.Wantlist.Entries() } func (w *ThreadSafe) SortedEntries() []*Entry { w.lk.RLock() defer w.lk.RUnlock() - var es entrySlice - - for _, e := range w.set { - es = append(es, e) - } - sort.Sort(es) - return es + return w.Wantlist.SortedEntries() } func (w *Wantlist) Add(k u.Key, priority int) { @@ -106,17 +93,14 @@ func (w *Wantlist) Contains(k u.Key) bool { func (w *Wantlist) Entries() []*Entry { var es entrySlice - for _, e := range w.set { es = append(es, e) } - sort.Sort(es) return es } func (w *Wantlist) SortedEntries() []*Entry { var es entrySlice - for _, e := range w.set { es = append(es, e) }