From 89c61b54247d7d322a22e9f419c40b8bcda0e2c9 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Mon, 29 May 2023 17:03:34 +0800 Subject: [PATCH 1/2] fix: code optimization Signed-off-by: guoguangwu --- internal/encoder/vm/vm.go | 4 ++-- internal/encoder/vm_color/vm.go | 4 ++-- internal/encoder/vm_color_indent/vm.go | 4 ++-- internal/encoder/vm_indent/vm.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/encoder/vm/vm.go b/internal/encoder/vm/vm.go index 645d20f..afe9334 100644 --- a/internal/encoder/vm/vm.go +++ b/internal/encoder/vm/vm.go @@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b code = code.End.Next } } else { - mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)] + mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:] if idx < mapCtx.Len { mapCtx.Idx = int(idx) mapCtx.Start = len(b) @@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 { b = appendColon(ctx, b) } else { - mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)] + mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:] mapCtx.Start = len(b) } value := mapitervalue(&mapCtx.Iter) diff --git a/internal/encoder/vm_color/vm.go b/internal/encoder/vm_color/vm.go index a63e83e..ce2a008 100644 --- a/internal/encoder/vm_color/vm.go +++ b/internal/encoder/vm_color/vm.go @@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b code = code.End.Next } } else { - mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)] + mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:] if idx < mapCtx.Len { mapCtx.Idx = int(idx) mapCtx.Start = len(b) @@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 { b = appendColon(ctx, b) } else { - mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)] + mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:] mapCtx.Start = len(b) } value := mapitervalue(&mapCtx.Iter) diff --git a/internal/encoder/vm_color_indent/vm.go b/internal/encoder/vm_color_indent/vm.go index 3b4e22e..5959209 100644 --- a/internal/encoder/vm_color_indent/vm.go +++ b/internal/encoder/vm_color_indent/vm.go @@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b code = code.End.Next } } else { - mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)] + mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:] if idx < mapCtx.Len { mapCtx.Idx = int(idx) mapCtx.Start = len(b) @@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 { b = appendColon(ctx, b) } else { - mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)] + mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:] mapCtx.Start = len(b) } value := mapitervalue(&mapCtx.Iter) diff --git a/internal/encoder/vm_indent/vm.go b/internal/encoder/vm_indent/vm.go index 836c5c8..c15d807 100644 --- a/internal/encoder/vm_indent/vm.go +++ b/internal/encoder/vm_indent/vm.go @@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b code = code.End.Next } } else { - mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)] + mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:] if idx < mapCtx.Len { mapCtx.Idx = int(idx) mapCtx.Start = len(b) @@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 { b = appendColon(ctx, b) } else { - mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)] + mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:] mapCtx.Start = len(b) } value := mapitervalue(&mapCtx.Iter) From 3a5cec6e364a880181c48b3965a43aa4d6a40ae0 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Mon, 29 May 2023 17:31:09 +0800 Subject: [PATCH 2/2] fix : vm.go.tmpl --- internal/cmd/generator/vm.go.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cmd/generator/vm.go.tmpl b/internal/cmd/generator/vm.go.tmpl index 645d20f..afe9334 100644 --- a/internal/cmd/generator/vm.go.tmpl +++ b/internal/cmd/generator/vm.go.tmpl @@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b code = code.End.Next } } else { - mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)] + mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:] if idx < mapCtx.Len { mapCtx.Idx = int(idx) mapCtx.Start = len(b) @@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 { b = appendColon(ctx, b) } else { - mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)] + mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:] mapCtx.Start = len(b) } value := mapitervalue(&mapCtx.Iter)