Eliminate byte buffer, copy scanner.Bytes directly

This commit is contained in:
Cameron Sparr 2016-04-07 16:09:12 -06:00
parent be379f3dac
commit 07f0d561dc
2 changed files with 6 additions and 7 deletions

View File

@ -20,7 +20,6 @@ func NewTestStatsd() *Statsd {
s.timings = make(map[string]cachedtimings)
s.MetricSeparator = "_"
s.UDPPacketSize = UDP_PACKET_SIZE
return &s
}

View File

@ -193,7 +193,7 @@ func (t *TcpListener) handler(conn *net.TCPConn, id string) {
t.forget(id)
}()
var buf []byte
var n int
scanner := bufio.NewScanner(conn)
for {
select {
@ -203,17 +203,17 @@ func (t *TcpListener) handler(conn *net.TCPConn, id string) {
if !scanner.Scan() {
return
}
buf = scanner.Bytes()
if len(buf) == 0 {
n = len(scanner.Bytes())
if n == 0 {
continue
}
bufCopy := make([]byte, len(buf))
copy(bufCopy, buf)
bufCopy := make([]byte, n)
copy(bufCopy, scanner.Bytes())
select {
case t.in <- bufCopy:
default:
log.Printf(dropwarn)
log.Printf(dropwarn, scanner.Text())
}
}
}