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:
parent
c8f7091969
commit
af20668cb5
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user