1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-23 11:37:32 +02:00

ensure buffer flushed to io.Writer

This commit is contained in:
Tao Wen 2017-07-16 10:47:24 +08:00
parent 4ae426c4b7
commit 6a4fbb9892

View File

@ -184,14 +184,14 @@ func (stream *Stream) Flush() error {
func (stream *Stream) ensure(minimal int) {
available := stream.Available()
if available < minimal {
if stream.n > 1024 {
stream.Flush()
}
stream.growAtLeast(minimal)
}
}
func (stream *Stream) growAtLeast(minimal int) {
if stream.out != nil {
stream.Flush()
}
toGrow := len(stream.buf)
if toGrow < minimal {
toGrow = minimal