From 652508dac7a08f9e21a60066fd7cf67bd14f2eff Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Tue, 8 Jun 2021 21:49:02 +0200 Subject: [PATCH] manually inline writeInt Signed-off-by: Oleg Kovalov --- encode.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/encode.go b/encode.go index 060eb71..0269f22 100644 --- a/encode.go +++ b/encode.go @@ -89,14 +89,20 @@ func (e *Encoder) writeInt(n int64) { } func (e *Encoder) marshalBytes(b []byte) { - e.writeInt(int64(len(b))) - e.buf.WriteByte(':') + // manual inline of writeInt + var bs [20]byte // max_str_len( math.MaxInt64, math.MinInt64 ) base 10 + buf := strconv.AppendInt(bs[0:0], int64(len(b)), 10) + buf = append(buf, ':') + e.buf.Write(buf) e.buf.Write(b) } func (e *Encoder) marshalString(s string) { - e.writeInt(int64(len(s))) - e.buf.WriteByte(':') + // manual inline of writeInt + var bs [20]byte // max_str_len( math.MaxInt64, math.MinInt64 ) base 10 + buf := strconv.AppendInt(bs[0:0], int64(len(s)), 10) + buf = append(buf, ':') + e.buf.Write(buf) e.buf.WriteString(s) }