forked from mirror/go-json
Merge pull request #260 from goccy/feature/improve-interface-perf
Improve encoding performance for empty interface type
This commit is contained in:
commit
8129998093
|
@ -177,11 +177,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
code = code.Next
|
code = code.Next
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if recursiveLevel > encoder.StartDetectingCyclesAfter {
|
||||||
for _, seen := range ctx.SeenPtr {
|
for _, seen := range ctx.SeenPtr {
|
||||||
if p == seen {
|
if p == seen {
|
||||||
return nil, errUnsupportedValue(code, p)
|
return nil, errUnsupportedValue(code, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ctx.SeenPtr = append(ctx.SeenPtr, p)
|
ctx.SeenPtr = append(ctx.SeenPtr, p)
|
||||||
iface := (*emptyInterface)(ptrToUnsafePtr(p))
|
iface := (*emptyInterface)(ptrToUnsafePtr(p))
|
||||||
if iface.ptr == nil {
|
if iface.ptr == nil {
|
||||||
|
@ -226,9 +228,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||||
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
||||||
code = c
|
code = c
|
||||||
|
recursiveLevel++
|
||||||
case encoder.OpInterfaceEnd:
|
case encoder.OpInterfaceEnd:
|
||||||
offset := load(ctxptr, code.Idx)
|
recursiveLevel--
|
||||||
|
|
||||||
// restore ctxptr
|
// restore ctxptr
|
||||||
|
offset := load(ctxptr, code.Idx)
|
||||||
restoreIndent(ctx, code, ctxptr)
|
restoreIndent(ctx, code, ctxptr)
|
||||||
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]
|
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]
|
||||||
|
|
||||||
|
|
|
@ -177,11 +177,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
code = code.Next
|
code = code.Next
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if recursiveLevel > encoder.StartDetectingCyclesAfter {
|
||||||
for _, seen := range ctx.SeenPtr {
|
for _, seen := range ctx.SeenPtr {
|
||||||
if p == seen {
|
if p == seen {
|
||||||
return nil, errUnsupportedValue(code, p)
|
return nil, errUnsupportedValue(code, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ctx.SeenPtr = append(ctx.SeenPtr, p)
|
ctx.SeenPtr = append(ctx.SeenPtr, p)
|
||||||
iface := (*emptyInterface)(ptrToUnsafePtr(p))
|
iface := (*emptyInterface)(ptrToUnsafePtr(p))
|
||||||
if iface.ptr == nil {
|
if iface.ptr == nil {
|
||||||
|
@ -226,9 +228,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||||
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
||||||
code = c
|
code = c
|
||||||
|
recursiveLevel++
|
||||||
case encoder.OpInterfaceEnd:
|
case encoder.OpInterfaceEnd:
|
||||||
offset := load(ctxptr, code.Idx)
|
recursiveLevel--
|
||||||
|
|
||||||
// restore ctxptr
|
// restore ctxptr
|
||||||
|
offset := load(ctxptr, code.Idx)
|
||||||
restoreIndent(ctx, code, ctxptr)
|
restoreIndent(ctx, code, ctxptr)
|
||||||
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]
|
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]
|
||||||
|
|
||||||
|
|
|
@ -177,11 +177,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
code = code.Next
|
code = code.Next
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if recursiveLevel > encoder.StartDetectingCyclesAfter {
|
||||||
for _, seen := range ctx.SeenPtr {
|
for _, seen := range ctx.SeenPtr {
|
||||||
if p == seen {
|
if p == seen {
|
||||||
return nil, errUnsupportedValue(code, p)
|
return nil, errUnsupportedValue(code, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ctx.SeenPtr = append(ctx.SeenPtr, p)
|
ctx.SeenPtr = append(ctx.SeenPtr, p)
|
||||||
iface := (*emptyInterface)(ptrToUnsafePtr(p))
|
iface := (*emptyInterface)(ptrToUnsafePtr(p))
|
||||||
if iface.ptr == nil {
|
if iface.ptr == nil {
|
||||||
|
@ -226,9 +228,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||||
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
||||||
code = c
|
code = c
|
||||||
|
recursiveLevel++
|
||||||
case encoder.OpInterfaceEnd:
|
case encoder.OpInterfaceEnd:
|
||||||
offset := load(ctxptr, code.Idx)
|
recursiveLevel--
|
||||||
|
|
||||||
// restore ctxptr
|
// restore ctxptr
|
||||||
|
offset := load(ctxptr, code.Idx)
|
||||||
restoreIndent(ctx, code, ctxptr)
|
restoreIndent(ctx, code, ctxptr)
|
||||||
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]
|
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]
|
||||||
|
|
||||||
|
|
|
@ -177,11 +177,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
code = code.Next
|
code = code.Next
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if recursiveLevel > encoder.StartDetectingCyclesAfter {
|
||||||
for _, seen := range ctx.SeenPtr {
|
for _, seen := range ctx.SeenPtr {
|
||||||
if p == seen {
|
if p == seen {
|
||||||
return nil, errUnsupportedValue(code, p)
|
return nil, errUnsupportedValue(code, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ctx.SeenPtr = append(ctx.SeenPtr, p)
|
ctx.SeenPtr = append(ctx.SeenPtr, p)
|
||||||
iface := (*emptyInterface)(ptrToUnsafePtr(p))
|
iface := (*emptyInterface)(ptrToUnsafePtr(p))
|
||||||
if iface.ptr == nil {
|
if iface.ptr == nil {
|
||||||
|
@ -226,9 +228,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||||
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
||||||
code = c
|
code = c
|
||||||
|
recursiveLevel++
|
||||||
case encoder.OpInterfaceEnd:
|
case encoder.OpInterfaceEnd:
|
||||||
offset := load(ctxptr, code.Idx)
|
recursiveLevel--
|
||||||
|
|
||||||
// restore ctxptr
|
// restore ctxptr
|
||||||
|
offset := load(ctxptr, code.Idx)
|
||||||
restoreIndent(ctx, code, ctxptr)
|
restoreIndent(ctx, code, ctxptr)
|
||||||
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]
|
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]
|
||||||
|
|
||||||
|
|
|
@ -177,11 +177,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
code = code.Next
|
code = code.Next
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if recursiveLevel > encoder.StartDetectingCyclesAfter {
|
||||||
for _, seen := range ctx.SeenPtr {
|
for _, seen := range ctx.SeenPtr {
|
||||||
if p == seen {
|
if p == seen {
|
||||||
return nil, errUnsupportedValue(code, p)
|
return nil, errUnsupportedValue(code, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ctx.SeenPtr = append(ctx.SeenPtr, p)
|
ctx.SeenPtr = append(ctx.SeenPtr, p)
|
||||||
iface := (*emptyInterface)(ptrToUnsafePtr(p))
|
iface := (*emptyInterface)(ptrToUnsafePtr(p))
|
||||||
if iface.ptr == nil {
|
if iface.ptr == nil {
|
||||||
|
@ -226,9 +228,12 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||||
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
||||||
code = c
|
code = c
|
||||||
|
recursiveLevel++
|
||||||
case encoder.OpInterfaceEnd:
|
case encoder.OpInterfaceEnd:
|
||||||
offset := load(ctxptr, code.Idx)
|
recursiveLevel--
|
||||||
|
|
||||||
// restore ctxptr
|
// restore ctxptr
|
||||||
|
offset := load(ctxptr, code.Idx)
|
||||||
restoreIndent(ctx, code, ctxptr)
|
restoreIndent(ctx, code, ctxptr)
|
||||||
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]
|
ctx.SeenPtr = ctx.SeenPtr[:len(ctx.SeenPtr)-1]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue