Removes sync.Pool

This commit is contained in:
Manu Mtz-Almeida 2014-08-18 20:43:34 +02:00
parent d85245b5aa
commit a5ae88722b
3 changed files with 3 additions and 10 deletions

View File

@ -1,5 +1,6 @@
language: go language: go
go: go:
- 1.2
- 1.3 - 1.3
- tip - tip

View File

@ -70,8 +70,9 @@ type Context struct {
/************************************/ /************************************/
func (engine *Engine) createContext(w http.ResponseWriter, req *http.Request, params httprouter.Params, handlers []HandlerFunc) *Context { func (engine *Engine) createContext(w http.ResponseWriter, req *http.Request, params httprouter.Params, handlers []HandlerFunc) *Context {
c := engine.cache.Get().(*Context) c := &Context{Engine: engine}
c.writermem.reset(w) c.writermem.reset(w)
c.Writer = &c.writermem
c.Request = req c.Request = req
c.Params = params c.Params = params
c.handlers = handlers c.handlers = handlers

9
gin.go
View File

@ -7,7 +7,6 @@ import (
"math" "math"
"net/http" "net/http"
"path" "path"
"sync"
) )
const ( const (
@ -36,7 +35,6 @@ type (
Engine struct { Engine struct {
*RouterGroup *RouterGroup
HTMLRender render.Render HTMLRender render.Render
cache sync.Pool
finalNoRoute []HandlerFunc finalNoRoute []HandlerFunc
noRoute []HandlerFunc noRoute []HandlerFunc
router *httprouter.Router router *httprouter.Router
@ -55,7 +53,6 @@ func (engine *Engine) handle404(w http.ResponseWriter, req *http.Request) {
c.Writer.WriteHeaderNow() c.Writer.WriteHeaderNow()
} }
} }
engine.cache.Put(c)
} }
// Returns a new blank Engine instance without any middleware attached. // Returns a new blank Engine instance without any middleware attached.
@ -65,11 +62,6 @@ func New() *Engine {
engine.RouterGroup = &RouterGroup{nil, "/", nil, engine} engine.RouterGroup = &RouterGroup{nil, "/", nil, engine}
engine.router = httprouter.New() engine.router = httprouter.New()
engine.router.NotFound = engine.handle404 engine.router.NotFound = engine.handle404
engine.cache.New = func() interface{} {
c := &Context{Engine: engine}
c.Writer = &c.writermem
return c
}
return engine return engine
} }
@ -172,7 +164,6 @@ func (group *RouterGroup) Handle(method, p string, handlers []HandlerFunc) {
c := group.engine.createContext(w, req, params, handlers) c := group.engine.createContext(w, req, params, handlers)
c.Next() c.Next()
c.Writer.WriteHeaderNow() c.Writer.WriteHeaderNow()
group.engine.cache.Put(c)
}) })
} }