diff options
Diffstat (limited to 'vendor/github.com/bytedance/sonic/ast/encode.go')
| -rw-r--r-- | vendor/github.com/bytedance/sonic/ast/encode.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/vendor/github.com/bytedance/sonic/ast/encode.go b/vendor/github.com/bytedance/sonic/ast/encode.go index eae0bd258..9401a6610 100644 --- a/vendor/github.com/bytedance/sonic/ast/encode.go +++ b/vendor/github.com/bytedance/sonic/ast/encode.go @@ -20,8 +20,9 @@ import ( "sync" "unicode/utf8" + "github.com/bytedance/gopkg/lang/dirtmake" "github.com/bytedance/sonic/internal/rt" - "github.com/bytedance/sonic/option" + "github.com/bytedance/sonic/option" ) func quoteString(e *[]byte, s string) { @@ -95,6 +96,11 @@ func (self *Node) MarshalJSON() ([]byte, error) { return bytesNull, nil } + // fast path for raw node + if self.isRaw() { + return rt.Str2Mem(self.toString()), nil + } + buf := newBuffer() err := self.encode(buf) if err != nil { @@ -105,7 +111,7 @@ func (self *Node) MarshalJSON() ([]byte, error) { if !rt.CanSizeResue(cap(*buf)) { ret = *buf } else { - ret = make([]byte, len(*buf)) + ret = dirtmake.Bytes(len(*buf), len(*buf)) copy(ret, *buf) freeBuffer(buf) } |
