Browse Source

Use strings.Builder in structdiff.Entries#String()

DarthSim 5 years ago
parent
commit
c91d109057
1 changed files with 8 additions and 1 deletions
  1. 8 1
      struct-diff/diff.go

+ 8 - 1
struct-diff/diff.go

@@ -5,6 +5,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"reflect"
+	"strings"
 	"sync"
 )
 
@@ -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{}
@@ -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()