mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 14:56:29 +00:00
63bed34608
IDs.Less can be rewritten as string(list[i][:]) < string(list[j][:]) Note that this does not copy the ID's. The Uniq method was no longer used. The String method has been reimplemented without first copying into a separate slice of a custom type.
41 lines
652 B
Go
41 lines
652 B
Go
package restic
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"strings"
|
|
)
|
|
|
|
// IDs is a slice of IDs that implements sort.Interface and fmt.Stringer.
|
|
type IDs []ID
|
|
|
|
func (ids IDs) Len() int {
|
|
return len(ids)
|
|
}
|
|
|
|
func (ids IDs) Less(i, j int) bool {
|
|
return string(ids[i][:]) < string(ids[j][:])
|
|
}
|
|
|
|
func (ids IDs) Swap(i, j int) {
|
|
ids[i], ids[j] = ids[j], ids[i]
|
|
}
|
|
|
|
func (ids IDs) String() string {
|
|
var sb strings.Builder
|
|
sb.Grow(1 + (1+2*shortStr)*len(ids))
|
|
|
|
buf := make([]byte, 2*shortStr)
|
|
|
|
sb.WriteByte('[')
|
|
for i, id := range ids {
|
|
if i > 0 {
|
|
sb.WriteByte(' ')
|
|
}
|
|
hex.Encode(buf, id[:shortStr])
|
|
sb.Write(buf)
|
|
}
|
|
sb.WriteByte(']')
|
|
|
|
return sb.String()
|
|
}
|