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.

This commit is contained in:
Sean E. Russell 2021-01-26 16:16:48 -06:00
parent c8f7091969
commit af20668cb5

View File

@ -25,9 +25,7 @@ func devs() []string {
rv := make([]string, 0, len(sensors)) rv := make([]string, 0, len(sensors))
for _, sensor := range sensors { for _, sensor := range sensors {
label := sensor.SensorKey label := sensor.SensorKey
if strings.Contains(sensor.SensorKey, "input") { label = strings.TrimSuffix(sensor.SensorKey, "_input")
label = sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
}
rv = append(rv, label) rv = append(rv, label)
sensorMap[sensor.SensorKey] = label sensorMap[sensor.SensorKey] = label
} }