Skip to content

Commit

Permalink
Perf: defer is not free
Browse files Browse the repository at this point in the history
  • Loading branch information
yunginnanet committed Jun 17, 2024
1 parent 31a2739 commit 00e908a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion heffalump/heffalump.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ func (h *Heffalump) WriteHell(bw *bufio.Writer) (int64, error) {
}()

buf := h.pool.Get().([]byte)
defer h.pool.Put(buf)

if _, err = bw.WriteString("<html>\n<body>\n"); err != nil {
h.pool.Put(buf)
return n, err
}
if n, err = io.CopyBuffer(bw, h.mm, buf); err != nil {
h.pool.Put(buf)
return n, nil
}

h.pool.Put(buf)
return n, nil
}

0 comments on commit 00e908a

Please sign in to comment.