2
0
mirror of synced 2025-02-23 14:18:13 +00:00

Calculate peer priority lazily for worse conn comparison

This commit is contained in:
Matt Joiner 2018-07-15 12:57:52 +10:00
parent bd5ae2cb6d
commit f22be3892f
2 changed files with 13 additions and 6 deletions

View File

@ -24,17 +24,22 @@ func (me *multiLess) FinalOk() (left, ok bool) {
}
func (me *multiLess) Next(f cmper) {
me.StrictNext(f())
if me.ok {
return
}
same, less := f()
if same {
return
}
me.ok = true
me.less = less
}
func (me *multiLess) StrictNext(same, less bool) {
if me.ok {
return
}
if same {
return
}
me.ok, me.less = true, less
me.Next(func() (bool, bool) { return same, less })
}
func (me *multiLess) NextBool(l, r bool) {

View File

@ -15,7 +15,9 @@ func worseConn(l, r *connection) bool {
ml.StrictNext(
l.completedHandshake.Equal(r.completedHandshake),
l.completedHandshake.Before(r.completedHandshake))
ml.StrictNext(l.peerPriority() == r.peerPriority(), l.peerPriority() < r.peerPriority())
ml.Next(func() (bool, bool) {
return l.peerPriority() == r.peerPriority(), l.peerPriority() < r.peerPriority()
})
ml.StrictNext(l == r, uintptr(unsafe.Pointer(l)) < uintptr(unsafe.Pointer(r)))
less, ok := ml.FinalOk()
if !ok {