From 07f0d561dc7cbb00cedf8ae3b6adca2dedd47beb Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Thu, 7 Apr 2016 16:09:12 -0600 Subject: [PATCH] Eliminate byte buffer, copy scanner.Bytes directly --- plugins/inputs/statsd/statsd_test.go | 1 - plugins/inputs/tcp_listener/tcp_listener.go | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/inputs/statsd/statsd_test.go b/plugins/inputs/statsd/statsd_test.go index 743e80135..9332f9d4f 100644 --- a/plugins/inputs/statsd/statsd_test.go +++ b/plugins/inputs/statsd/statsd_test.go @@ -20,7 +20,6 @@ func NewTestStatsd() *Statsd { s.timings = make(map[string]cachedtimings) s.MetricSeparator = "_" - s.UDPPacketSize = UDP_PACKET_SIZE return &s } diff --git a/plugins/inputs/tcp_listener/tcp_listener.go b/plugins/inputs/tcp_listener/tcp_listener.go index 6f3166456..b7f5ef9ed 100644 --- a/plugins/inputs/tcp_listener/tcp_listener.go +++ b/plugins/inputs/tcp_listener/tcp_listener.go @@ -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()) } } }