Permalink
Browse files

Filters: Performance fix (7% on JSON benchmark!)

  • Loading branch information...
robfig committed May 19, 2013
1 parent 82a8195 commit 8f02aa01988e95b3e651096677544cf8942451d0
Showing with 9 additions and 9 deletions.
  1. +2 −2 controller.go
  2. +3 −3 i18n_test.go
  3. +3 −3 results_test.go
  4. +1 −1 server.go
View
@@ -33,8 +33,8 @@ type Controller struct {
Txn *sql.Tx // Nil by default, but may be used by the app / plugins
}
-func NewController(req *Request, resp *Response) Controller {
- return Controller{
+func NewController(req *Request, resp *Response) *Controller {
+ return &Controller{
Request: req,
Response: resp,
Args: map[string]interface{}{},
View
@@ -118,17 +118,17 @@ func TestBeforeRequest(t *testing.T) {
filter := I18nFilter{}
c := NewController(buildEmptyRequest(), nil)
- if filter.Call(&c, NilChain); c.Request.Locale != "" {
+ if filter.Call(c, NilChain); c.Request.Locale != "" {
t.Errorf("Expected to find current language '%s' in controller, found '%s' instead", "", c.Request.Locale)
}
c = NewController(buildRequestWithCookie("APP_LANG", "en-US"), nil)
- if filter.Call(&c, NilChain); c.Request.Locale != "en-US" {
+ if filter.Call(c, NilChain); c.Request.Locale != "en-US" {
t.Errorf("Expected to find current language '%s' in controller, found '%s' instead", "en-US", c.Request.Locale)
}
c = NewController(buildRequestWithAcceptLanguages("en-GB", "en-US"), nil)
- if filter.Call(&c, NilChain); c.Request.Locale != "en-GB" {
+ if filter.Call(c, NilChain); c.Request.Locale != "en-GB" {
t.Errorf("Expected to find current language '%s' in controller, found '%s' instead", "en-GB", c.Request.Locale)
}
}
View
@@ -12,7 +12,7 @@ func TestBenchmarkRender(t *testing.T) {
resp := httptest.NewRecorder()
c := NewController(NewRequest(showRequest), NewResponse(resp))
c.SetAction("Hotels", "Show")
- result := Hotels{&c}.Show(3)
+ result := Hotels{c}.Show(3)
result.Apply(c.Request, c.Response)
if !strings.Contains(resp.Body.String(), "300 Main St.") {
t.Errorf("Failed to find hotel address in action response:\n%s", resp.Body)
@@ -28,7 +28,7 @@ func BenchmarkRenderChunked(b *testing.B) {
Config.SetOption("results.chunked", "true")
b.ResetTimer()
- hotels := Hotels{&c}
+ hotels := Hotels{c}
for i := 0; i < b.N; i++ {
hotels.Show(3).Apply(c.Request, c.Response)
}
@@ -43,7 +43,7 @@ func BenchmarkRenderNotChunked(b *testing.B) {
Config.SetOption("results.chunked", "false")
b.ResetTimer()
- hotels := Hotels{&c}
+ hotels := Hotels{c}
for i := 0; i < b.N; i++ {
hotels.Show(3).Apply(c.Request, c.Response)
}
View
@@ -35,7 +35,7 @@ func handleInternal(w http.ResponseWriter, r *http.Request, ws *websocket.Conn)
)
req.Websocket = ws
- Filters[0].Call(&c, Filters[1:])
+ Filters[0].Call(c, Filters[1:])
if c.Result != nil {
c.Result.Apply(req, resp)
}

0 comments on commit 8f02aa0

Please sign in to comment.