mirror of https://github.com/goccy/go-json.git
Fix storeIndent
This commit is contained in:
parent
994dc9ea9d
commit
f93d82dee6
|
@ -224,7 +224,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, c.Idx, uintptr(iface.ptr))
|
||||
store(ctxptr, end.Idx, oldOffset)
|
||||
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||
storeIndent(ctxptr, c, uintptr(oldBaseIndent))
|
||||
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
||||
code = c
|
||||
case encoder.OpInterfaceEnd:
|
||||
offset := load(ctxptr, code.Idx)
|
||||
|
@ -533,7 +533,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, c.Idx, ptr)
|
||||
store(ctxptr, c.End.Next.Idx, oldOffset)
|
||||
store(ctxptr, c.End.Next.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||
storeIndent(ctxptr, c, uintptr(oldBaseIndent))
|
||||
storeIndent(ctxptr, c.End.Next, uintptr(oldBaseIndent))
|
||||
code = c
|
||||
recursiveLevel++
|
||||
case encoder.OpRecursiveEnd:
|
||||
|
|
|
@ -123,39 +123,6 @@ func appendMapEnd(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte
|
|||
return b
|
||||
}
|
||||
|
||||
func appendInterface(ctx *encoder.RuntimeContext, codeSet *encoder.OpcodeSet, _ *encoder.Opcode, b []byte, iface *emptyInterface, ptrOffset uintptr) ([]byte, error) {
|
||||
ctx.KeepRefs = append(ctx.KeepRefs, unsafe.Pointer(iface))
|
||||
ifaceCodeSet, err := encoder.CompileToGetCodeSet(uintptr(unsafe.Pointer(iface.typ)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
totalLength := uintptr(codeSet.CodeLength)
|
||||
nextTotalLength := uintptr(ifaceCodeSet.CodeLength)
|
||||
|
||||
curlen := uintptr(len(ctx.Ptrs))
|
||||
offsetNum := ptrOffset / uintptrSize
|
||||
|
||||
newLen := offsetNum + totalLength + nextTotalLength
|
||||
if curlen < newLen {
|
||||
ctx.Ptrs = append(ctx.Ptrs, make([]uintptr, newLen-curlen)...)
|
||||
}
|
||||
oldPtrs := ctx.Ptrs
|
||||
|
||||
newPtrs := ctx.Ptrs[(ptrOffset+totalLength*uintptrSize)/uintptrSize:]
|
||||
newPtrs[0] = uintptr(iface.ptr)
|
||||
|
||||
ctx.Ptrs = newPtrs
|
||||
|
||||
bb, err := Run(ctx, b, ifaceCodeSet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.Ptrs = oldPtrs
|
||||
return bb, nil
|
||||
}
|
||||
|
||||
func appendMarshalJSON(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
|
||||
return encoder.AppendMarshalJSON(ctx, code, b, v)
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, c.Idx, uintptr(iface.ptr))
|
||||
store(ctxptr, end.Idx, oldOffset)
|
||||
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||
storeIndent(ctxptr, c, uintptr(oldBaseIndent))
|
||||
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
||||
code = c
|
||||
case encoder.OpInterfaceEnd:
|
||||
offset := load(ctxptr, code.Idx)
|
||||
|
@ -533,7 +533,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, c.Idx, ptr)
|
||||
store(ctxptr, c.End.Next.Idx, oldOffset)
|
||||
store(ctxptr, c.End.Next.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||
storeIndent(ctxptr, c, uintptr(oldBaseIndent))
|
||||
storeIndent(ctxptr, c.End.Next, uintptr(oldBaseIndent))
|
||||
code = c
|
||||
recursiveLevel++
|
||||
case encoder.OpRecursiveEnd:
|
||||
|
|
|
@ -176,39 +176,6 @@ func appendMapEnd(_ *encoder.RuntimeContext, _ *encoder.Opcode, b []byte) []byte
|
|||
return b
|
||||
}
|
||||
|
||||
func appendInterface(ctx *encoder.RuntimeContext, codeSet *encoder.OpcodeSet, _ *encoder.Opcode, b []byte, iface *emptyInterface, ptrOffset uintptr) ([]byte, error) {
|
||||
ctx.KeepRefs = append(ctx.KeepRefs, unsafe.Pointer(iface))
|
||||
ifaceCodeSet, err := encoder.CompileToGetCodeSet(uintptr(unsafe.Pointer(iface.typ)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
totalLength := uintptr(codeSet.CodeLength)
|
||||
nextTotalLength := uintptr(ifaceCodeSet.CodeLength)
|
||||
|
||||
curlen := uintptr(len(ctx.Ptrs))
|
||||
offsetNum := ptrOffset / uintptrSize
|
||||
|
||||
newLen := offsetNum + totalLength + nextTotalLength
|
||||
if curlen < newLen {
|
||||
ctx.Ptrs = append(ctx.Ptrs, make([]uintptr, newLen-curlen)...)
|
||||
}
|
||||
oldPtrs := ctx.Ptrs
|
||||
|
||||
newPtrs := ctx.Ptrs[(ptrOffset+totalLength*uintptrSize)/uintptrSize:]
|
||||
newPtrs[0] = uintptr(iface.ptr)
|
||||
|
||||
ctx.Ptrs = newPtrs
|
||||
|
||||
bb, err := Run(ctx, b, ifaceCodeSet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.Ptrs = oldPtrs
|
||||
return bb, nil
|
||||
}
|
||||
|
||||
func appendMarshalJSON(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte, v interface{}) ([]byte, error) {
|
||||
return encoder.AppendMarshalJSON(ctx, code, b, v)
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, c.Idx, uintptr(iface.ptr))
|
||||
store(ctxptr, end.Idx, oldOffset)
|
||||
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||
storeIndent(ctxptr, c, uintptr(oldBaseIndent))
|
||||
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
||||
code = c
|
||||
case encoder.OpInterfaceEnd:
|
||||
offset := load(ctxptr, code.Idx)
|
||||
|
@ -533,7 +533,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, c.Idx, ptr)
|
||||
store(ctxptr, c.End.Next.Idx, oldOffset)
|
||||
store(ctxptr, c.End.Next.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||
storeIndent(ctxptr, c, uintptr(oldBaseIndent))
|
||||
storeIndent(ctxptr, c.End.Next, uintptr(oldBaseIndent))
|
||||
code = c
|
||||
recursiveLevel++
|
||||
case encoder.OpRecursiveEnd:
|
||||
|
|
|
@ -163,43 +163,6 @@ func appendColon(_ *encoder.RuntimeContext, b []byte) []byte {
|
|||
return append(b, ':', ' ')
|
||||
}
|
||||
|
||||
func appendInterface(ctx *encoder.RuntimeContext, codeSet *encoder.OpcodeSet, code *encoder.Opcode, b []byte, iface *emptyInterface, ptrOffset uintptr) ([]byte, error) {
|
||||
ctx.KeepRefs = append(ctx.KeepRefs, unsafe.Pointer(iface))
|
||||
ifaceCodeSet, err := encoder.CompileToGetCodeSet(uintptr(unsafe.Pointer(iface.typ)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
totalLength := uintptr(codeSet.CodeLength)
|
||||
nextTotalLength := uintptr(ifaceCodeSet.CodeLength)
|
||||
|
||||
curlen := uintptr(len(ctx.Ptrs))
|
||||
offsetNum := ptrOffset / uintptrSize
|
||||
|
||||
newLen := offsetNum + totalLength + nextTotalLength
|
||||
if curlen < newLen {
|
||||
ctx.Ptrs = append(ctx.Ptrs, make([]uintptr, newLen-curlen)...)
|
||||
}
|
||||
oldPtrs := ctx.Ptrs
|
||||
|
||||
newPtrs := ctx.Ptrs[(ptrOffset+totalLength*uintptrSize)/uintptrSize:]
|
||||
newPtrs[0] = uintptr(iface.ptr)
|
||||
|
||||
ctx.Ptrs = newPtrs
|
||||
|
||||
oldBaseIndent := ctx.BaseIndent
|
||||
ctx.BaseIndent = code.Indent
|
||||
bb, err := Run(ctx, b, ifaceCodeSet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ctx.BaseIndent = oldBaseIndent
|
||||
|
||||
ctx.Ptrs = oldPtrs
|
||||
|
||||
return bb, nil
|
||||
}
|
||||
|
||||
func appendMapKeyValue(ctx *encoder.RuntimeContext, code *encoder.Opcode, b, key, value []byte) []byte {
|
||||
b = appendIndent(ctx, b, code.Indent+1)
|
||||
b = append(b, key...)
|
||||
|
@ -292,7 +255,7 @@ func restoreIndent(ctx *encoder.RuntimeContext, code *encoder.Opcode, ctxptr uin
|
|||
}
|
||||
|
||||
func storeIndent(ctxptr uintptr, code *encoder.Opcode, indent uintptr) {
|
||||
store(ctxptr, code.End.Next.Length, indent)
|
||||
store(ctxptr, code.Length, indent)
|
||||
}
|
||||
|
||||
func appendArrayElemIndent(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
|
||||
|
|
|
@ -224,7 +224,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, c.Idx, uintptr(iface.ptr))
|
||||
store(ctxptr, end.Idx, oldOffset)
|
||||
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||
storeIndent(ctxptr, c, uintptr(oldBaseIndent))
|
||||
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
||||
code = c
|
||||
case encoder.OpInterfaceEnd:
|
||||
offset := load(ctxptr, code.Idx)
|
||||
|
@ -533,7 +533,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, c.Idx, ptr)
|
||||
store(ctxptr, c.End.Next.Idx, oldOffset)
|
||||
store(ctxptr, c.End.Next.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||
storeIndent(ctxptr, c, uintptr(oldBaseIndent))
|
||||
storeIndent(ctxptr, c.End.Next, uintptr(oldBaseIndent))
|
||||
code = c
|
||||
recursiveLevel++
|
||||
case encoder.OpRecursiveEnd:
|
||||
|
|
|
@ -111,43 +111,6 @@ func appendColon(_ *encoder.RuntimeContext, b []byte) []byte {
|
|||
return append(b, ':', ' ')
|
||||
}
|
||||
|
||||
func appendInterface(ctx *encoder.RuntimeContext, codeSet *encoder.OpcodeSet, code *encoder.Opcode, b []byte, iface *emptyInterface, ptrOffset uintptr) ([]byte, error) {
|
||||
ctx.KeepRefs = append(ctx.KeepRefs, unsafe.Pointer(iface))
|
||||
ifaceCodeSet, err := encoder.CompileToGetCodeSet(uintptr(unsafe.Pointer(iface.typ)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
totalLength := uintptr(codeSet.CodeLength)
|
||||
nextTotalLength := uintptr(ifaceCodeSet.CodeLength)
|
||||
|
||||
curlen := uintptr(len(ctx.Ptrs))
|
||||
offsetNum := ptrOffset / uintptrSize
|
||||
|
||||
newLen := offsetNum + totalLength + nextTotalLength
|
||||
if curlen < newLen {
|
||||
ctx.Ptrs = append(ctx.Ptrs, make([]uintptr, newLen-curlen)...)
|
||||
}
|
||||
oldPtrs := ctx.Ptrs
|
||||
|
||||
newPtrs := ctx.Ptrs[(ptrOffset+totalLength*uintptrSize)/uintptrSize:]
|
||||
newPtrs[0] = uintptr(iface.ptr)
|
||||
|
||||
ctx.Ptrs = newPtrs
|
||||
|
||||
oldBaseIndent := ctx.BaseIndent
|
||||
ctx.BaseIndent = code.Indent
|
||||
bb, err := Run(ctx, b, ifaceCodeSet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ctx.BaseIndent = oldBaseIndent
|
||||
|
||||
ctx.Ptrs = oldPtrs
|
||||
|
||||
return bb, nil
|
||||
}
|
||||
|
||||
func appendMapKeyValue(ctx *encoder.RuntimeContext, code *encoder.Opcode, b, key, value []byte) []byte {
|
||||
b = appendIndent(ctx, b, code.Indent+1)
|
||||
b = append(b, key...)
|
||||
|
@ -229,7 +192,7 @@ func restoreIndent(ctx *encoder.RuntimeContext, code *encoder.Opcode, ctxptr uin
|
|||
}
|
||||
|
||||
func storeIndent(ctxptr uintptr, code *encoder.Opcode, indent uintptr) {
|
||||
store(ctxptr, code.End.Next.Length, indent)
|
||||
store(ctxptr, code.Length, indent)
|
||||
}
|
||||
|
||||
func appendArrayElemIndent(ctx *encoder.RuntimeContext, code *encoder.Opcode, b []byte) []byte {
|
||||
|
|
|
@ -224,7 +224,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, c.Idx, uintptr(iface.ptr))
|
||||
store(ctxptr, end.Idx, oldOffset)
|
||||
store(ctxptr, end.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||
storeIndent(ctxptr, c, uintptr(oldBaseIndent))
|
||||
storeIndent(ctxptr, end, uintptr(oldBaseIndent))
|
||||
code = c
|
||||
case encoder.OpInterfaceEnd:
|
||||
offset := load(ctxptr, code.Idx)
|
||||
|
@ -533,7 +533,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
|||
store(ctxptr, c.Idx, ptr)
|
||||
store(ctxptr, c.End.Next.Idx, oldOffset)
|
||||
store(ctxptr, c.End.Next.ElemIdx, uintptr(unsafe.Pointer(code.Next)))
|
||||
storeIndent(ctxptr, c, uintptr(oldBaseIndent))
|
||||
storeIndent(ctxptr, c.End.Next, uintptr(oldBaseIndent))
|
||||
code = c
|
||||
recursiveLevel++
|
||||
case encoder.OpRecursiveEnd:
|
||||
|
|
Loading…
Reference in New Issue