@@ -26,8 +26,8 @@ import (
2626// zeros (the 'g' format avoids the use of 'f' in this case). All other
2727// formats always show the exact precision of the Decimal.
2828func (d * Decimal ) Text (format byte ) string {
29- cap := 10 // TODO(gri) determine a good/better value here
30- return string (d .Append (make ([] byte , 0 , cap ) , format ))
29+ var buf [ 16 ] byte
30+ return string (d .Append (buf [: 0 ] , format ))
3131}
3232
3333// String formats x like x.Text('G'). It matches the to-scientific-string
@@ -57,7 +57,8 @@ func (d *Decimal) Append(buf []byte, fmt byte) []byte {
5757 return append (buf , "unknown" ... )
5858 }
5959
60- digits := d .Coeff .String ()
60+ var scratch [16 ]byte
61+ digits := d .Coeff .Append (scratch [:0 ], 10 )
6162 switch fmt {
6263 case 'e' , 'E' :
6364 return fmtE (buf , fmt , d , digits )
@@ -83,7 +84,7 @@ func (d *Decimal) Append(buf []byte, fmt byte) []byte {
8384}
8485
8586// %e: d.ddddde±d
86- func fmtE (buf []byte , fmt byte , d * Decimal , digits string ) []byte {
87+ func fmtE (buf []byte , fmt byte , d * Decimal , digits [] byte ) []byte {
8788 adj := int64 (d .Exponent ) + int64 (len (digits )) - 1
8889 buf = append (buf , digits [0 ])
8990 if len (digits ) > 1 {
@@ -103,7 +104,7 @@ func fmtE(buf []byte, fmt byte, d *Decimal, digits string) []byte {
103104}
104105
105106// %f: ddddddd.ddddd
106- func fmtF (buf []byte , d * Decimal , digits string ) []byte {
107+ func fmtF (buf []byte , d * Decimal , digits [] byte ) []byte {
107108 if d .Exponent < 0 {
108109 if left := - int (d .Exponent ) - len (digits ); left >= 0 {
109110 buf = append (buf , "0." ... )
0 commit comments