This commit is contained in:
Masaaki Goshima 2020-09-03 22:05:46 +09:00
parent 34b662b98e
commit efcf2dec06
1 changed files with 4 additions and 9 deletions

View File

@ -152,20 +152,15 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, recursiveLevel int, seenPtr map
curlen := uintptr(len(ctx.ptrs)) curlen := uintptr(len(ctx.ptrs))
offsetNum := ptrOffset / uintptrSize offsetNum := ptrOffset / uintptrSize
oldOffset := ptrOffset oldOffset := ptrOffset
ptrOffset = ptrOffset + totalLength*uintptrSize // curlen * uintptrSize ptrOffset += totalLength * uintptrSize
}
newLen := offsetNum + totalLength + nextTotalLength newLen := offsetNum + totalLength + nextTotalLength
if curlen < newLen { if curlen < newLen {
ctx.ptrs = append(ctx.ptrs, make([]uintptr, newLen-curlen)...) ctx.ptrs = append(ctx.ptrs, make([]uintptr, newLen-curlen)...)
store(ctx.ptr()+ptrOffset, 0, uintptr(header.ptr))
} else {
store(ctx.ptr()+ptrOffset, 0, uintptr(header.ptr))
} }
ctxptr = ctx.ptr() + ptrOffset // assign new ctxptr ctxptr = ctx.ptr() + ptrOffset // assign new ctxptr
if load(ctxptr, 0) != uintptr(header.ptr) {
panic(nil) store(ctxptr, 0, uintptr(header.ptr))
}
// save current ctxptr
store(ctxptr, lastCode.idx, oldOffset) store(ctxptr, lastCode.idx, oldOffset)
// link lastCode ( opInterfaceEnd ) => code.next // link lastCode ( opInterfaceEnd ) => code.next