Improve performance for []byte type

This commit is contained in:
Masaaki Goshima 2020-08-25 17:19:41 +09:00
parent 6681db131f
commit e28091e4c7
1 changed files with 5 additions and 2 deletions

View File

@ -74,9 +74,12 @@ func (e *Encoder) run(code *opcode) error {
if ptr == 0 || header.Data == 0 { if ptr == 0 || header.Data == 0 {
e.encodeNull() e.encodeNull()
} else { } else {
s := base64.StdEncoding.EncodeToString(e.ptrToBytes(code.ptr)) b := e.ptrToBytes(code.ptr)
encodedLen := base64.StdEncoding.EncodedLen(len(b))
e.encodeByte('"') e.encodeByte('"')
e.encodeBytes(*(*[]byte)(unsafe.Pointer(&s))) buf := make([]byte, encodedLen)
base64.StdEncoding.Encode(buf, b)
e.encodeBytes(buf)
e.encodeByte('"') e.encodeByte('"')
} }
code = code.next code = code.next