Skip to content

Commit

Permalink
Avoid defer
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Andres Virviescas Santana committed Feb 6, 2019
1 parent 6af130c commit 7eb5830
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions server_fasthttp.go
Expand Up @@ -187,10 +187,6 @@ func (u *FastHTTPUpgrader) Upgrade(ctx *fasthttp.RequestCtx, handler FastHTTPHan
ctx.Hijack(func(netConn net.Conn) {
// var br *bufio.Reader // Always nil
writeBuf := poolWriteBuffer.Get().([]byte)
defer func() {
writeBuf = writeBuf[0:0]
poolWriteBuffer.Put(writeBuf)
}()

c := newConn(netConn, true, u.ReadBufferSize, u.WriteBufferSize, u.WriteBufferPool, nil, writeBuf)
if subprotocol != nil {
Expand All @@ -206,6 +202,9 @@ func (u *FastHTTPUpgrader) Upgrade(ctx *fasthttp.RequestCtx, handler FastHTTPHan
netConn.SetDeadline(time.Time{})

handler(c)

writeBuf = writeBuf[0:0]
poolWriteBuffer.Put(writeBuf)
})

return nil
Expand Down

0 comments on commit 7eb5830

Please sign in to comment.