@cryptotaxi247 / kubo / commits / 8d4d5b86e

fix: don't sort the output of Entries()

only sort SortedEntries() License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Dec 16, 2014 at 23:32 UTC 8d4d5b86ef590c8ef461002a1895c3da61ecb8bf
1 file changed +2 -18
exchange/bitswap/wantlist/wantlist.go
+2 -18
@@ -63,26 +63,13 @@ func (w *ThreadSafe) Contains(k u.Key) bool {
63 func (w *ThreadSafe) Entries() []*Entry {
64 w.lk.RLock()
65 defer w.lk.RUnlock()
66 - var es entrySlice
67 - for _, e := range w.set {
68 - es = append(es, e)
69 - }
70 - // TODO rename SortedEntries (state that they're sorted so callers know
71 - // they're paying an expense)
72 - sort.Sort(es)
73 - return es
66 + return w.Wantlist.Entries()
67 }
68
69 func (w *ThreadSafe) SortedEntries() []*Entry {
70 w.lk.RLock()
71 defer w.lk.RUnlock()
79 - var es entrySlice
80 -
81 - for _, e := range w.set {
82 - es = append(es, e)
83 - }
84 - sort.Sort(es)
85 - return es
72 + return w.Wantlist.SortedEntries()
73 }
74
75 func (w *Wantlist) Add(k u.Key, priority int) {
@@ -106,17 +93,14 @@ func (w *Wantlist) Contains(k u.Key) bool {
93
94 func (w *Wantlist) Entries() []*Entry {
95 var es entrySlice
109 -
96 for _, e := range w.set {
97 es = append(es, e)
98 }
113 - sort.Sort(es)
99 return es
100 }
101
102 func (w *Wantlist) SortedEntries() []*Entry {
103 var es entrySlice
119 -
104 for _, e := range w.set {
105 es = append(es, e)
106 }