Skip to content

Commit

Permalink
Filters: Performance fix (7% on JSON benchmark!)
Browse files Browse the repository at this point in the history
  • Loading branch information
robfig committed May 19, 2013
1 parent 82a8195 commit 8f02aa0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{},
Expand Down
6 changes: 3 additions & 3 deletions i18n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
6 changes: 3 additions & 3 deletions results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 8f02aa0

Please sign in to comment.