1
0
mirror of https://github.com/json-iterator/go.git synced 2025-02-19 19:59:49 +02:00

Merge branch 'float-allocs' of git://github.com/brian-brazil/go into 1.1

This commit is contained in:
Tao Wen 2018-02-14 11:37:27 +08:00
commit 6a8f9fa342
2 changed files with 8 additions and 2 deletions

View File

@ -14,6 +14,7 @@ type Stream struct {
Error error
indention int
Attachment interface{} // open for customized encoder
floatBuf []byte
}
// NewStream create new stream instance.
@ -28,6 +29,7 @@ func NewStream(cfg API, out io.Writer, bufSize int) *Stream {
n: 0,
Error: nil,
indention: 0,
floatBuf: make([]byte, 0, 32),
}
}

View File

@ -21,7 +21,9 @@ func (stream *Stream) WriteFloat32(val float32) {
fmt = 'e'
}
}
stream.WriteRaw(strconv.FormatFloat(float64(val), fmt, -1, 32))
stream.floatBuf = strconv.AppendFloat(stream.floatBuf, float64(val), fmt, -1, 32)
stream.Write(stream.floatBuf)
stream.floatBuf = stream.floatBuf[:0]
}
// WriteFloat32Lossy write float32 to stream with ONLY 6 digits precision although much much faster
@ -63,7 +65,9 @@ func (stream *Stream) WriteFloat64(val float64) {
fmt = 'e'
}
}
stream.WriteRaw(strconv.FormatFloat(float64(val), fmt, -1, 64))
stream.floatBuf = strconv.AppendFloat(stream.floatBuf, float64(val), fmt, -1, 64)
stream.Write(stream.floatBuf)
stream.floatBuf = stream.floatBuf[:0]
}
// WriteFloat64Lossy write float64 to stream with ONLY 6 digits precision although much much faster