Skip to content

Commit

Permalink
Use strings.Builder in structdiff.Entries#String()
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthSim committed Oct 23, 2019
1 parent 4d36527 commit c91d109
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion struct-diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"reflect"
"strings"
"sync"
)

Expand All @@ -14,6 +15,12 @@ var bufPool = sync.Pool{
},
}

var builderPool = sync.Pool{
New: func() interface{} {
return new(strings.Builder)
},
}

type Entry struct {
Name string
Value interface{}
Expand All @@ -22,7 +29,7 @@ type Entry struct {
type Entries []Entry

func (d Entries) String() string {
buf := bufPool.Get().(*bytes.Buffer)
buf := builderPool.Get().(*strings.Builder)
last := len(d) - 1

buf.Reset()
Expand Down

0 comments on commit c91d109

Please sign in to comment.