From 47c54231d226dd8c2189832a593c787188cf0709 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 15 Dec 2014 18:19:13 +0100 Subject: [PATCH] linux: more idiomatic array operations on GetPortLists --- serial_linux.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/serial_linux.go b/serial_linux.go index 0ff5de1..634cbde 100644 --- a/serial_linux.go +++ b/serial_linux.go @@ -60,8 +60,7 @@ func GetPortsList() ([]string, error) { return nil, err } - ports := make([]string, len(files)) - found := 0 + ports := make([]string, 0, len(files)) for _, f := range files { // Skip folders if f.IsDir() { @@ -92,12 +91,10 @@ func GetPortsList() ([]string, error) { } } - // Save found serial port in the resulting list - ports[found] = portName - found++ + // Save serial port in the resulting list + ports = append(ports, portName) } - ports = ports[:found] return ports, nil }