summaryrefslogtreecommitdiff
path: root/vendor/github.com/bytedance/sonic/internal/decoder/compiler.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/bytedance/sonic/internal/decoder/compiler.go')
-rw-r--r--vendor/github.com/bytedance/sonic/internal/decoder/compiler.go45
1 files changed, 24 insertions, 21 deletions
diff --git a/vendor/github.com/bytedance/sonic/internal/decoder/compiler.go b/vendor/github.com/bytedance/sonic/internal/decoder/compiler.go
index e9e2b77fc..b350c0461 100644
--- a/vendor/github.com/bytedance/sonic/internal/decoder/compiler.go
+++ b/vendor/github.com/bytedance/sonic/internal/decoder/compiler.go
@@ -527,40 +527,47 @@ func (self *_Compiler) compile(vt reflect.Type) (ret _Program, err error) {
return
}
-func (self *_Compiler) compileOne(p *_Program, sp int, vt reflect.Type) {
- /* check for recursive nesting */
- ok := self.tab[vt]
- if ok {
- p.rtt(_OP_recurse, vt)
- return
- }
-
+func (self *_Compiler) checkMarshaler(p *_Program, vt reflect.Type) bool {
pt := reflect.PtrTo(vt)
/* check for `json.Unmarshaler` with pointer receiver */
if pt.Implements(jsonUnmarshalerType) {
p.rtt(_OP_unmarshal_p, pt)
- return
+ return true
}
/* check for `json.Unmarshaler` */
if vt.Implements(jsonUnmarshalerType) {
p.add(_OP_lspace)
self.compileUnmarshalJson(p, vt)
- return
+ return true
}
/* check for `encoding.TextMarshaler` with pointer receiver */
if pt.Implements(encodingTextUnmarshalerType) {
p.add(_OP_lspace)
self.compileUnmarshalTextPtr(p, pt)
- return
+ return true
}
/* check for `encoding.TextUnmarshaler` */
if vt.Implements(encodingTextUnmarshalerType) {
p.add(_OP_lspace)
self.compileUnmarshalText(p, vt)
+ return true
+ }
+ return false
+}
+
+func (self *_Compiler) compileOne(p *_Program, sp int, vt reflect.Type) {
+ /* check for recursive nesting */
+ ok := self.tab[vt]
+ if ok {
+ p.rtt(_OP_recurse, vt)
+ return
+ }
+
+ if self.checkMarshaler(p, vt) {
return
}
@@ -683,17 +690,9 @@ func (self *_Compiler) compilePtr(p *_Program, sp int, et reflect.Type) {
/* dereference all the way down */
for et.Kind() == reflect.Ptr {
- if et.Implements(jsonUnmarshalerType) {
- p.rtt(_OP_unmarshal_p, et)
+ if self.checkMarshaler(p, et) {
return
}
-
- if et.Implements(encodingTextUnmarshalerType) {
- p.add(_OP_lspace)
- self.compileUnmarshalTextPtr(p, et)
- return
- }
-
et = et.Elem()
p.rtt(_OP_deref, et)
}
@@ -706,7 +705,7 @@ func (self *_Compiler) compilePtr(p *_Program, sp int, et reflect.Type) {
/* enter the recursion */
p.add(_OP_lspace)
self.tab[et] = true
-
+
/* not inline the pointer type
* recursing the defined pointer type's elem will casue issue379.
*/
@@ -716,8 +715,12 @@ func (self *_Compiler) compilePtr(p *_Program, sp int, et reflect.Type) {
j := p.pc()
p.add(_OP_goto)
+
+ // set val pointer as nil
p.pin(i)
p.add(_OP_nil_1)
+
+ // nothing todo
p.pin(j)
}