1
0
mirror of https://github.com/labstack/echo.git synced 2025-02-03 13:11:39 +02:00

Minor performance fixes

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2018-03-14 14:03:59 -07:00
parent bdb49be734
commit 62d3587b6f
2 changed files with 12 additions and 16 deletions

View File

@ -560,7 +560,6 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Acquire context // Acquire context
c := e.pool.Get().(*context) c := e.pool.Get().(*context)
defer e.pool.Put(c)
c.Reset(r, w) c.Reset(r, w)
// Middleware // Middleware
@ -587,6 +586,9 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err := h(c); err != nil { if err := h(c); err != nil {
e.HTTPErrorHandler(err, c) e.HTTPErrorHandler(err, c)
} }
// Release context
e.pool.Put(c)
} }
// Start starts an HTTP server. // Start starts an HTTP server.

View File

@ -4,7 +4,6 @@ import (
"bufio" "bufio"
"net" "net"
"net/http" "net/http"
"strconv"
) )
type ( type (
@ -13,7 +12,6 @@ type (
// See: https://golang.org/pkg/net/http/#ResponseWriter // See: https://golang.org/pkg/net/http/#ResponseWriter
Response struct { Response struct {
echo *Echo echo *Echo
contentLength int64
beforeFuncs []func() beforeFuncs []func()
afterFuncs []func() afterFuncs []func()
Writer http.ResponseWriter Writer http.ResponseWriter
@ -64,7 +62,6 @@ func (r *Response) WriteHeader(code int) {
r.Status = code r.Status = code
r.Writer.WriteHeader(code) r.Writer.WriteHeader(code)
r.Committed = true r.Committed = true
r.contentLength, _ = strconv.ParseInt(r.Header().Get(HeaderContentLength), 10, 0)
} }
// Write writes the data to the connection as part of an HTTP reply. // Write writes the data to the connection as part of an HTTP reply.
@ -74,11 +71,9 @@ func (r *Response) Write(b []byte) (n int, err error) {
} }
n, err = r.Writer.Write(b) n, err = r.Writer.Write(b)
r.Size += int64(n) r.Size += int64(n)
if r.Size == r.contentLength {
for _, fn := range r.afterFuncs { for _, fn := range r.afterFuncs {
fn() fn()
} }
}
return return
} }
@ -106,7 +101,6 @@ func (r *Response) CloseNotify() <-chan bool {
} }
func (r *Response) reset(w http.ResponseWriter) { func (r *Response) reset(w http.ResponseWriter) {
r.contentLength = 0
r.beforeFuncs = nil r.beforeFuncs = nil
r.afterFuncs = nil r.afterFuncs = nil
r.Writer = w r.Writer = w