mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
use the more efficient strings.Builder
Signed-off-by: cui fliter <imcusg@gmail.com>
This commit is contained in:
parent
9b10f20004
commit
0c919dc212
@ -15,8 +15,8 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 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) String() string {
|
||||
var b bytes.Buffer
|
||||
var b strings.Builder
|
||||
if p.Len() > 0 {
|
||||
b.WriteString(p[0].String())
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"encoding/gob"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"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) {
|
||||
var buf bytes.Buffer
|
||||
var buf strings.Builder
|
||||
if err := gob.NewEncoder(&buf).Encode(kv{k, v}); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -15,11 +15,11 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
)
|
||||
@ -58,7 +58,7 @@ func printJSON(v interface{}) {
|
||||
}
|
||||
|
||||
func printMemberListWithHexJSON(r clientv3.MemberListResponse) {
|
||||
var buffer bytes.Buffer
|
||||
var buffer strings.Builder
|
||||
var b []byte
|
||||
buffer.WriteString("{\"header\":{\"cluster_id\":\"")
|
||||
b = strconv.AppendUint(nil, r.Header.ClusterId, 16)
|
||||
|
@ -17,7 +17,6 @@
|
||||
package cobrautl
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -103,7 +102,7 @@ GLOBAL OPTIONS:
|
||||
}
|
||||
|
||||
func etcdFlagUsages(flagSet *pflag.FlagSet) string {
|
||||
x := new(bytes.Buffer)
|
||||
x := new(strings.Builder)
|
||||
|
||||
flagSet.VisitAll(func(flag *pflag.Flag) {
|
||||
if len(flag.Deprecated) > 0 {
|
||||
|
@ -15,12 +15,12 @@
|
||||
package report
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@ -119,7 +119,7 @@ func (sp *secondPoints) getTimeSeries() TimeSeries {
|
||||
}
|
||||
|
||||
func (t TimeSeries) String() string {
|
||||
buf := new(bytes.Buffer)
|
||||
buf := new(strings.Builder)
|
||||
wr := csv.NewWriter(buf)
|
||||
if err := wr.Write([]string{"UNIX-SECOND", "MIN-LATENCY-MS", "AVG-LATENCY-MS", "MAX-LATENCY-MS", "AVG-THROUGHPUT"}); err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -16,10 +16,10 @@
|
||||
package traceutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@ -44,7 +44,7 @@ func writeFields(fields []Field) string {
|
||||
if len(fields) == 0 {
|
||||
return ""
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
var buf strings.Builder
|
||||
buf.WriteString("{")
|
||||
for _, f := range fields {
|
||||
buf.WriteString(f.format())
|
||||
|
@ -15,7 +15,6 @@
|
||||
package membership
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha1"
|
||||
"encoding/binary"
|
||||
@ -215,7 +214,7 @@ func (c *RaftCluster) ClientURLs() []string {
|
||||
func (c *RaftCluster) String() string {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
b := &bytes.Buffer{}
|
||||
b := &strings.Builder{}
|
||||
fmt.Fprintf(b, "{ClusterID:%s ", c.cid)
|
||||
var ms []string
|
||||
for _, m := range c.members {
|
||||
|
@ -16,7 +16,6 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
@ -345,7 +344,7 @@ func listEntriesType(entrytype string, streamdecoder string, ents []raftpb.Entry
|
||||
"Request": printRequest,
|
||||
"ConfigChange": printConfChange,
|
||||
"UnknownNormal": printUnknownNormal}
|
||||
var stderr bytes.Buffer
|
||||
var stderr strings.Builder
|
||||
args := strings.Split(streamdecoder, " ")
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
stdin, err := cmd.StdinPipe()
|
||||
|
@ -15,10 +15,10 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/go-semver/semver"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
@ -45,7 +45,7 @@ func printEtcdVersion() []error {
|
||||
sort.Slice(annotations, func(i, j int) bool {
|
||||
return annotations[i].fullName < annotations[j].fullName
|
||||
})
|
||||
output := &bytes.Buffer{}
|
||||
output := &strings.Builder{}
|
||||
for _, a := range annotations {
|
||||
newErrs := a.Validate()
|
||||
if len(newErrs) == 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user