404 not found performance improvements

benchmark            old ns/op     new ns/op     delta
Benchmark404         737           249           -66.21%
Benchmark404Many     2330          454           -80.52%

benchmark            old allocs     new allocs     delta
Benchmark404         3              0              -100.00%
Benchmark404Many     10             0              -100.00%

benchmark            old bytes     new bytes     delta
Benchmark404         115           68            -40.87%
Benchmark404Many     235           57            -75.74%
This commit is contained in:
Manu Mtz-Almeida
2015-05-30 14:45:13 +02:00
parent deb137cdd2
commit 835f66fdc9
11 changed files with 88 additions and 22 deletions

View File

@ -6,6 +6,7 @@ package gin
import (
"bufio"
"io"
"net"
"net/http"
)
@ -24,6 +25,7 @@ type (
Status() int
Size() int
WriteString(string) (int, error)
Written() bool
WriteHeaderNow()
}
@ -35,6 +37,8 @@ type (
}
)
var _ ResponseWriter = &responseWriter{}
func (w *responseWriter) reset(writer http.ResponseWriter) {
w.ResponseWriter = writer
w.size = noWritten
@ -64,6 +68,13 @@ func (w *responseWriter) Write(data []byte) (n int, err error) {
return
}
func (w *responseWriter) WriteString(s string) (n int, err error) {
w.WriteHeaderNow()
n, err = io.WriteString(w.ResponseWriter, s)
w.size += n
return
}
func (w *responseWriter) Status() int {
return w.status
}