forked from forgejo/forgejo
Bump unrolled/render to v1.1.0 (#15581)
v1.1.0 has improved buffer pooling
This commit is contained in:
parent
f719ffc783
commit
445e47b692
10 changed files with 97 additions and 32 deletions
17
vendor/github.com/unrolled/render/engine.go
generated
vendored
17
vendor/github.com/unrolled/render/engine.go
generated
vendored
|
@ -30,6 +30,8 @@ type HTML struct {
|
|||
Head
|
||||
Name string
|
||||
Templates *template.Template
|
||||
|
||||
bp GenericBufferPool
|
||||
}
|
||||
|
||||
// JSON built-in renderer.
|
||||
|
@ -82,9 +84,14 @@ func (d Data) Render(w io.Writer, v interface{}) error {
|
|||
|
||||
// Render a HTML response.
|
||||
func (h HTML) Render(w io.Writer, binding interface{}) error {
|
||||
// Retrieve a buffer from the pool to write to.
|
||||
out := bufPool.Get()
|
||||
err := h.Templates.ExecuteTemplate(out, h.Name, binding)
|
||||
var buf *bytes.Buffer
|
||||
if h.bp != nil {
|
||||
// If we have a bufferpool, allocate from it
|
||||
buf = h.bp.Get()
|
||||
defer h.bp.Put(buf)
|
||||
}
|
||||
|
||||
err := h.Templates.ExecuteTemplate(buf, h.Name, binding)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -92,10 +99,8 @@ func (h HTML) Render(w io.Writer, binding interface{}) error {
|
|||
if hw, ok := w.(http.ResponseWriter); ok {
|
||||
h.Head.Write(hw)
|
||||
}
|
||||
out.WriteTo(w)
|
||||
buf.WriteTo(w)
|
||||
|
||||
// Return the buffer to the pool.
|
||||
bufPool.Put(out)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue