mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Replace calls to strings.Compare (#9397)
< is clearer and faster. As the documentation says, "Basically no one should use strings.Compare." Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
dbbfd1ccf6
commit
1fb3c1b598
|
@ -18,7 +18,6 @@ import (
|
|||
"container/heap"
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
@ -197,15 +196,13 @@ func mergeStrings(a, b []string) []string {
|
|||
res := make([]string, 0, maxl*10/9)
|
||||
|
||||
for len(a) > 0 && len(b) > 0 {
|
||||
d := strings.Compare(a[0], b[0])
|
||||
|
||||
if d == 0 {
|
||||
if a[0] == b[0] {
|
||||
res = append(res, a[0])
|
||||
a, b = a[1:], b[1:]
|
||||
} else if d < 0 {
|
||||
} else if a[0] < b[0] {
|
||||
res = append(res, a[0])
|
||||
a = a[1:]
|
||||
} else if d > 0 {
|
||||
} else {
|
||||
res = append(res, b[0])
|
||||
b = b[1:]
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"encoding/binary"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/prometheus/prometheus/pkg/labels"
|
||||
|
@ -94,8 +93,8 @@ func (p *MemPostings) SortedKeys() []labels.Label {
|
|||
p.mtx.RUnlock()
|
||||
|
||||
sort.Slice(keys, func(i, j int) bool {
|
||||
if d := strings.Compare(keys[i].Name, keys[j].Name); d != 0 {
|
||||
return d < 0
|
||||
if keys[i].Name != keys[j].Name {
|
||||
return keys[i].Name < keys[j].Name
|
||||
}
|
||||
return keys[i].Value < keys[j].Value
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue