forked from quic-go/quic-go
use bits.OnesCount to determine if a number is a power of two
This should be 3-4x faster than the current implementation.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package quic
|
package quic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/bits"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||||
@@ -68,10 +69,8 @@ func (s *closedLocalConn) handlePacketImpl(_ *receivedPacket) {
|
|||||||
s.counter++
|
s.counter++
|
||||||
// exponential backoff
|
// exponential backoff
|
||||||
// only send a CONNECTION_CLOSE for the 1st, 2nd, 4th, 8th, 16th, ... packet arriving
|
// only send a CONNECTION_CLOSE for the 1st, 2nd, 4th, 8th, 16th, ... packet arriving
|
||||||
for n := s.counter; n > 1; n = n / 2 {
|
if bits.OnesCount64(s.counter) != 1 {
|
||||||
if n%2 != 0 {
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
s.logger.Debugf("Received %d packets after sending CONNECTION_CLOSE. Retransmitting.", s.counter)
|
s.logger.Debugf("Received %d packets after sending CONNECTION_CLOSE. Retransmitting.", s.counter)
|
||||||
if err := s.conn.Write(s.connClosePacket); err != nil {
|
if err := s.conn.Write(s.connClosePacket); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user