From af20668cb5746018e316b1ae4007e6ac54f608a5 Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Tue, 26 Jan 2021 16:16:48 -0600 Subject: [PATCH] strings.TrimSuffix() is some 7x faster than a call to Index() plus a slice, and we can remove a call to Contains() in the bargain. --- devices/temp_linux.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/devices/temp_linux.go b/devices/temp_linux.go index b738002..c0f4cae 100644 --- a/devices/temp_linux.go +++ b/devices/temp_linux.go @@ -25,9 +25,7 @@ func devs() []string { rv := make([]string, 0, len(sensors)) for _, sensor := range sensors { label := sensor.SensorKey - if strings.Contains(sensor.SensorKey, "input") { - label = sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")] - } + label = strings.TrimSuffix(sensor.SensorKey, "_input") rv = append(rv, label) sensorMap[sensor.SensorKey] = label }