remove some allocations

ref #129
This commit is contained in:
Lucas Clemente
2016-05-24 15:22:56 +02:00
parent 6c2932a872
commit 55fe1390b3
3 changed files with 10 additions and 1 deletions

View File

@@ -37,7 +37,7 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *publicHeader, r
}
entropyBit := privateFlag&0x01 > 0
fs := []frames.Frame{}
fs := make([]frames.Frame, 0, 1)
// Read all frames in the packet
ReadLoop:

View File

@@ -545,6 +545,10 @@ func (s *Session) sendConnectionClose(quicErr *qerr.QuicError) error {
}
func (s *Session) logPacket(packet *packedPacket) {
if !utils.Debug() {
// We don't need to allocate the slices for calling the format functions
return
}
utils.Debugf("-> Sending packet 0x%x (%d bytes)", packet.number, len(packet.raw))
for _, frame := range packet.frames {
if streamFrame, isStreamFrame := frame.(*frames.StreamFrame); isStreamFrame {

View File

@@ -58,3 +58,8 @@ func Errorf(format string, args ...interface{}) {
mutex.Unlock()
}
}
// Debug returns true if the log level is LogLevelDebug
func Debug() bool {
return logLevel == LogLevelDebug
}