Eliminate byte buffer, copy scanner.Bytes directly
This commit is contained in:
parent
be379f3dac
commit
07f0d561dc
|
@ -20,7 +20,6 @@ func NewTestStatsd() *Statsd {
|
||||||
s.timings = make(map[string]cachedtimings)
|
s.timings = make(map[string]cachedtimings)
|
||||||
|
|
||||||
s.MetricSeparator = "_"
|
s.MetricSeparator = "_"
|
||||||
s.UDPPacketSize = UDP_PACKET_SIZE
|
|
||||||
|
|
||||||
return &s
|
return &s
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,7 +193,7 @@ func (t *TcpListener) handler(conn *net.TCPConn, id string) {
|
||||||
t.forget(id)
|
t.forget(id)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var buf []byte
|
var n int
|
||||||
scanner := bufio.NewScanner(conn)
|
scanner := bufio.NewScanner(conn)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -203,17 +203,17 @@ func (t *TcpListener) handler(conn *net.TCPConn, id string) {
|
||||||
if !scanner.Scan() {
|
if !scanner.Scan() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
buf = scanner.Bytes()
|
n = len(scanner.Bytes())
|
||||||
if len(buf) == 0 {
|
if n == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
bufCopy := make([]byte, len(buf))
|
bufCopy := make([]byte, n)
|
||||||
copy(bufCopy, buf)
|
copy(bufCopy, scanner.Bytes())
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case t.in <- bufCopy:
|
case t.in <- bufCopy:
|
||||||
default:
|
default:
|
||||||
log.Printf(dropwarn)
|
log.Printf(dropwarn, scanner.Text())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue