Skip to content

Commit

Permalink
Eliminate byte buffer, copy scanner.Bytes directly
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Apr 7, 2016
1 parent bb9a5dc commit db71e25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 0 additions & 1 deletion plugins/inputs/statsd/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func NewTestStatsd() *Statsd {
s.timings = make(map[string]cachedtimings)

s.MetricSeparator = "_"
s.UDPPacketSize = UDP_PACKET_SIZE

return &s
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/inputs/tcp_listener/tcp_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -203,12 +203,12 @@ 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:
Expand Down

0 comments on commit db71e25

Please sign in to comment.