mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-27 12:05:23 +00:00
use heap.Fix instead of heap.Remove + heap.Push when updating queues, this is theoretically faster
This commit is contained in:
parent
1f65ffb310
commit
09f9f4e8e4
@ -38,12 +38,16 @@ func (q *packetQueue) drop() bool {
|
||||
longestIdx = idx
|
||||
}
|
||||
}
|
||||
stream := heap.Remove(q, longestIdx).(pqStream)
|
||||
stream := q.streams[longestIdx]
|
||||
info := stream.infos[0]
|
||||
if len(stream.infos) > 1 {
|
||||
stream.infos = stream.infos[1:]
|
||||
stream.size -= uint64(len(info.packet))
|
||||
heap.Push(q, stream)
|
||||
q.streams[longestIdx] = stream
|
||||
q.size -= uint64(len(info.packet))
|
||||
heap.Fix(q, longestIdx)
|
||||
} else {
|
||||
heap.Remove(q, longestIdx)
|
||||
}
|
||||
pool_putBytes(info.packet)
|
||||
return true
|
||||
@ -67,12 +71,16 @@ func (q *packetQueue) push(packet []byte) {
|
||||
|
||||
func (q *packetQueue) pop() ([]byte, bool) {
|
||||
if q.size > 0 {
|
||||
stream := heap.Pop(q).(pqStream)
|
||||
stream := q.streams[0]
|
||||
info := stream.infos[0]
|
||||
if len(stream.infos) > 1 {
|
||||
stream.infos = stream.infos[1:]
|
||||
stream.size -= uint64(len(info.packet))
|
||||
heap.Push(q, stream)
|
||||
q.streams[0] = stream
|
||||
q.size -= uint64(len(info.packet))
|
||||
heap.Fix(q, 0)
|
||||
} else {
|
||||
heap.Remove(q, 0)
|
||||
}
|
||||
return info.packet, true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user