Merge pull request #15908 from cuishuang/main

*: use strings.Builder instead of bytes.Buffer
dependabot/go_modules/github.com/prometheus/procfs-0.11.0
Benjamin Wang 2023-05-26 09:41:01 +08:00 committed by GitHub
commit 3413f2e08d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 15 additions and 17 deletions

View File

@ -15,8 +15,8 @@
package types package types
import ( import (
"bytes"
"strconv" "strconv"
"strings"
) )
// ID represents a generic identifier which is canonically // ID represents a generic identifier which is canonically
@ -42,7 +42,7 @@ func (p IDSlice) Less(i, j int) bool { return uint64(p[i]) < uint64(p[j]) }
func (p IDSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } func (p IDSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p IDSlice) String() string { func (p IDSlice) String() string {
var b bytes.Buffer var b strings.Builder
if p.Len() > 0 { if p.Len() > 0 {
b.WriteString(p[0].String()) b.WriteString(p[0].String())
} }

View File

@ -19,6 +19,7 @@ import (
"encoding/gob" "encoding/gob"
"encoding/json" "encoding/json"
"log" "log"
"strings"
"sync" "sync"
"go.etcd.io/etcd/server/v3/etcdserver/api/snap" "go.etcd.io/etcd/server/v3/etcdserver/api/snap"
@ -63,7 +64,7 @@ func (s *kvstore) Lookup(key string) (string, bool) {
} }
func (s *kvstore) Propose(k string, v string) { func (s *kvstore) Propose(k string, v string) {
var buf bytes.Buffer var buf strings.Builder
if err := gob.NewEncoder(&buf).Encode(kv{k, v}); err != nil { if err := gob.NewEncoder(&buf).Encode(kv{k, v}); err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -15,11 +15,11 @@
package command package command
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"strings"
clientv3 "go.etcd.io/etcd/client/v3" clientv3 "go.etcd.io/etcd/client/v3"
) )
@ -58,7 +58,7 @@ func printJSON(v interface{}) {
} }
func printMemberListWithHexJSON(r clientv3.MemberListResponse) { func printMemberListWithHexJSON(r clientv3.MemberListResponse) {
var buffer bytes.Buffer var buffer strings.Builder
var b []byte var b []byte
buffer.WriteString("{\"header\":{\"cluster_id\":\"") buffer.WriteString("{\"header\":{\"cluster_id\":\"")
b = strconv.AppendUint(nil, r.Header.ClusterId, 16) b = strconv.AppendUint(nil, r.Header.ClusterId, 16)

View File

@ -17,7 +17,6 @@
package cobrautl package cobrautl
import ( import (
"bytes"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -103,7 +102,7 @@ GLOBAL OPTIONS:
} }
func etcdFlagUsages(flagSet *pflag.FlagSet) string { func etcdFlagUsages(flagSet *pflag.FlagSet) string {
x := new(bytes.Buffer) x := new(strings.Builder)
flagSet.VisitAll(func(flag *pflag.Flag) { flagSet.VisitAll(func(flag *pflag.Flag) {
if len(flag.Deprecated) > 0 { if len(flag.Deprecated) > 0 {

View File

@ -15,12 +15,12 @@
package report package report
import ( import (
"bytes"
"encoding/csv" "encoding/csv"
"fmt" "fmt"
"log" "log"
"math" "math"
"sort" "sort"
"strings"
"sync" "sync"
"time" "time"
) )
@ -119,7 +119,7 @@ func (sp *secondPoints) getTimeSeries() TimeSeries {
} }
func (t TimeSeries) String() string { func (t TimeSeries) String() string {
buf := new(bytes.Buffer) buf := new(strings.Builder)
wr := csv.NewWriter(buf) wr := csv.NewWriter(buf)
if err := wr.Write([]string{"UNIX-SECOND", "MIN-LATENCY-MS", "AVG-LATENCY-MS", "MAX-LATENCY-MS", "AVG-THROUGHPUT"}); err != nil { if err := wr.Write([]string{"UNIX-SECOND", "MIN-LATENCY-MS", "AVG-LATENCY-MS", "MAX-LATENCY-MS", "AVG-THROUGHPUT"}); err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -16,10 +16,10 @@
package traceutil package traceutil
import ( import (
"bytes"
"context" "context"
"fmt" "fmt"
"math/rand" "math/rand"
"strings"
"time" "time"
"go.uber.org/zap" "go.uber.org/zap"
@ -44,7 +44,7 @@ func writeFields(fields []Field) string {
if len(fields) == 0 { if len(fields) == 0 {
return "" return ""
} }
var buf bytes.Buffer var buf strings.Builder
buf.WriteString("{") buf.WriteString("{")
for _, f := range fields { for _, f := range fields {
buf.WriteString(f.format()) buf.WriteString(f.format())

View File

@ -15,7 +15,6 @@
package membership package membership
import ( import (
"bytes"
"context" "context"
"crypto/sha1" "crypto/sha1"
"encoding/binary" "encoding/binary"
@ -215,7 +214,7 @@ func (c *RaftCluster) ClientURLs() []string {
func (c *RaftCluster) String() string { func (c *RaftCluster) String() string {
c.Lock() c.Lock()
defer c.Unlock() defer c.Unlock()
b := &bytes.Buffer{} b := &strings.Builder{}
fmt.Fprintf(b, "{ClusterID:%s ", c.cid) fmt.Fprintf(b, "{ClusterID:%s ", c.cid)
var ms []string var ms []string
for _, m := range c.members { for _, m := range c.members {

View File

@ -16,7 +16,6 @@ package main
import ( import (
"bufio" "bufio"
"bytes"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"flag" "flag"
@ -345,7 +344,7 @@ func listEntriesType(entrytype string, streamdecoder string, ents []raftpb.Entry
"Request": printRequest, "Request": printRequest,
"ConfigChange": printConfChange, "ConfigChange": printConfChange,
"UnknownNormal": printUnknownNormal} "UnknownNormal": printUnknownNormal}
var stderr bytes.Buffer var stderr strings.Builder
args := strings.Split(streamdecoder, " ") args := strings.Split(streamdecoder, " ")
cmd := exec.Command(args[0], args[1:]...) cmd := exec.Command(args[0], args[1:]...)
stdin, err := cmd.StdinPipe() stdin, err := cmd.StdinPipe()

View File

@ -15,10 +15,10 @@
package cmd package cmd
import ( import (
"bytes"
"fmt" "fmt"
"io" "io"
"sort" "sort"
"strings"
"github.com/coreos/go-semver/semver" "github.com/coreos/go-semver/semver"
"google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoreflect"
@ -45,7 +45,7 @@ func printEtcdVersion() []error {
sort.Slice(annotations, func(i, j int) bool { sort.Slice(annotations, func(i, j int) bool {
return annotations[i].fullName < annotations[j].fullName return annotations[i].fullName < annotations[j].fullName
}) })
output := &bytes.Buffer{} output := &strings.Builder{}
for _, a := range annotations { for _, a := range annotations {
newErrs := a.Validate() newErrs := a.Validate()
if len(newErrs) == 0 { if len(newErrs) == 0 {