提交 8d4d5b86 作者: Brian Tiger Chow 提交者: Juan Batiz-Benet

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

only sort SortedEntries()

License: MIT
Signed-off-by: 's avatarBrian Tiger Chow <brian@perfmode.com>
上级 acc71482
...@@ -63,26 +63,13 @@ func (w *ThreadSafe) Contains(k u.Key) bool { ...@@ -63,26 +63,13 @@ func (w *ThreadSafe) Contains(k u.Key) bool {
func (w *ThreadSafe) Entries() []*Entry { func (w *ThreadSafe) Entries() []*Entry {
w.lk.RLock() w.lk.RLock()
defer w.lk.RUnlock() defer w.lk.RUnlock()
var es entrySlice return w.Wantlist.Entries()
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
} }
func (w *ThreadSafe) SortedEntries() []*Entry { func (w *ThreadSafe) SortedEntries() []*Entry {
w.lk.RLock() w.lk.RLock()
defer w.lk.RUnlock() defer w.lk.RUnlock()
var es entrySlice return w.Wantlist.SortedEntries()
for _, e := range w.set {
es = append(es, e)
}
sort.Sort(es)
return es
} }
func (w *Wantlist) Add(k u.Key, priority int) { func (w *Wantlist) Add(k u.Key, priority int) {
...@@ -106,17 +93,14 @@ func (w *Wantlist) Contains(k u.Key) bool { ...@@ -106,17 +93,14 @@ func (w *Wantlist) Contains(k u.Key) bool {
func (w *Wantlist) Entries() []*Entry { func (w *Wantlist) Entries() []*Entry {
var es entrySlice var es entrySlice
for _, e := range w.set { for _, e := range w.set {
es = append(es, e) es = append(es, e)
} }
sort.Sort(es)
return es return es
} }
func (w *Wantlist) SortedEntries() []*Entry { func (w *Wantlist) SortedEntries() []*Entry {
var es entrySlice var es entrySlice
for _, e := range w.set { for _, e := range w.set {
es = append(es, e) es = append(es, e)
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论