From f610966b6538df9eb1820eba8b344f241cce165d Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Fri, 26 Nov 2021 18:33:49 +0900 Subject: [PATCH] pass benchmark test --- internal/encoder/code.go | 11 ++++++----- internal/encoder/opcode.go | 16 ++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/internal/encoder/code.go b/internal/encoder/code.go index 2ac8085..19797ef 100644 --- a/internal/encoder/code.go +++ b/internal/encoder/code.go @@ -483,16 +483,17 @@ func linkRecursiveCode2(ctx *compileContext) { beforeLastCode := code.End lastCode := beforeLastCode.Next - lastCode.Idx = beforeLastCode.Idx + uintptrSize + totalLength := code.TotalLength() + lastCode.Idx = uint32((totalLength + 1) * uintptrSize) lastCode.ElemIdx = lastCode.Idx + uintptrSize lastCode.Length = lastCode.Idx + 2*uintptrSize code.End.Next.Op = OpRecursiveEnd - // extend length to alloc slot for elemIdx + length - totalLength := uintptr(recursive.TotalLength()) + 3 - nextTotalLength := uintptr(codes.First().TotalLength()) + 3 - compiled.CurLen = totalLength + // extend length to alloc slot for elemIdx + length + curTotalLength := uintptr(recursive.TotalLength()) + 3 + nextTotalLength := uintptr(totalLength) + 3 + compiled.CurLen = curTotalLength compiled.NextLen = nextTotalLength compiled.Linked = true } diff --git a/internal/encoder/opcode.go b/internal/encoder/opcode.go index 5c87f69..eb78001 100644 --- a/internal/encoder/opcode.go +++ b/internal/encoder/opcode.go @@ -490,7 +490,7 @@ func (c *Opcode) dumpHead(code *Opcode) string { length = code.Length / uintptrSize } return fmt.Sprintf( - `[%02d]%s%s ([idx:%d][elemIdx:%d][length:%d])`, + `[%03d]%s%s ([idx:%d][elemIdx:%d][length:%d])`, code.DisplayIdx, strings.Repeat("-", int(code.Indent)), code.Op, @@ -502,7 +502,7 @@ func (c *Opcode) dumpHead(code *Opcode) string { func (c *Opcode) dumpMapHead(code *Opcode) string { return fmt.Sprintf( - `[%02d]%s%s ([idx:%d][elemIdx:%d][length:%d][mapIter:%d])`, + `[%03d]%s%s ([idx:%d][elemIdx:%d][length:%d][mapIter:%d])`, code.DisplayIdx, strings.Repeat("-", int(code.Indent)), code.Op, @@ -515,7 +515,7 @@ func (c *Opcode) dumpMapHead(code *Opcode) string { func (c *Opcode) dumpMapEnd(code *Opcode) string { return fmt.Sprintf( - `[%02d]%s%s ([idx:%d][mapPos:%d][length:%d])`, + `[%03d]%s%s ([idx:%d][mapPos:%d][length:%d])`, code.DisplayIdx, strings.Repeat("-", int(code.Indent)), code.Op, @@ -533,7 +533,7 @@ func (c *Opcode) dumpElem(code *Opcode) string { length = code.Length / uintptrSize } return fmt.Sprintf( - `[%02d]%s%s ([idx:%d][elemIdx:%d][length:%d][size:%d])`, + `[%03d]%s%s ([idx:%d][elemIdx:%d][length:%d][size:%d])`, code.DisplayIdx, strings.Repeat("-", int(code.Indent)), code.Op, @@ -546,7 +546,7 @@ func (c *Opcode) dumpElem(code *Opcode) string { func (c *Opcode) dumpField(code *Opcode) string { return fmt.Sprintf( - `[%02d]%s%s ([idx:%d][key:%s][offset:%d])`, + `[%03d]%s%s ([idx:%d][key:%s][offset:%d])`, code.DisplayIdx, strings.Repeat("-", int(code.Indent)), code.Op, @@ -558,7 +558,7 @@ func (c *Opcode) dumpField(code *Opcode) string { func (c *Opcode) dumpKey(code *Opcode) string { return fmt.Sprintf( - `[%02d]%s%s ([idx:%d][elemIdx:%d][length:%d][mapIter:%d])`, + `[%03d]%s%s ([idx:%d][elemIdx:%d][length:%d][mapIter:%d])`, code.DisplayIdx, strings.Repeat("-", int(code.Indent)), code.Op, @@ -571,7 +571,7 @@ func (c *Opcode) dumpKey(code *Opcode) string { func (c *Opcode) dumpValue(code *Opcode) string { return fmt.Sprintf( - `[%02d]%s%s ([idx:%d][mapIter:%d])`, + `[%03d]%s%s ([idx:%d][mapIter:%d])`, code.DisplayIdx, strings.Repeat("-", int(code.Indent)), code.Op, @@ -610,7 +610,7 @@ func (c *Opcode) Dump() string { code = code.Next default: codes = append(codes, fmt.Sprintf( - "[%02d]%s%s ([idx:%d])", + "[%03d]%s%s ([idx:%d])", code.DisplayIdx, strings.Repeat("-", int(code.Indent)), code.Op,