From e824abb341b3e42bf0fdc843955353167ffc8618 Mon Sep 17 00:00:00 2001 From: "liuqiang.06" Date: Tue, 6 Aug 2024 12:30:05 +0800 Subject: [PATCH] fix: remove unused code --- go1.23 | 1 - internal/decoder/api/error_test.go | 161 ---------------------------- internal/decoder/api/stream.go | 15 --- internal/decoder/api/stream_test.go | 2 - internal/decoder/optdec/native.go | 1 - internal/decoder/optdec/node.go | 12 --- internal/encoder/vm/vm.go | 2 - internal/optcaching/fcache.go | 2 - 8 files changed, 196 deletions(-) delete mode 160000 go1.23 delete mode 100644 internal/decoder/api/error_test.go diff --git a/go1.23 b/go1.23 deleted file mode 160000 index c9940fe2a..000000000 --- a/go1.23 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c9940fe2a9f2eb77327efca860abfbae8d94bf28 diff --git a/internal/decoder/api/error_test.go b/internal/decoder/api/error_test.go deleted file mode 100644 index fcb6a554f..000000000 --- a/internal/decoder/api/error_test.go +++ /dev/null @@ -1,161 +0,0 @@ - - -package api - -// import ( -// "encoding/json" -// "strings" -// "testing" - -// "github.com/davecgh/go-spew/spew" -// "github.com/stretchr/testify/assert" -// ) - - -// type errTest struct { -// in string -// ptr interface{} -// pos int -// } - - -// func TestErrors_ParseError(t *testing.T) { -// testCases := []errTest { -// { -// in: `{123}`, -// pos: 1, -// }, -// { -// in: `tru`, -// pos: 0, -// }, -// { -// in: ` fx`, -// pos: 1, -// }, -// { -// in: `{"12" 12}`, -// pos: 6, -// }, -// } - -// for _, tt := range testCases { -// var v1, v2 interface{} -// got := NewDecoder(tt.in).Decode(&v1) -// exp := json.Unmarshal([]byte(tt.in), &v2) -// assert.Error(t, exp) -// e := got.(SyntaxError); -// assert.Equal(t, tt.pos, e.Pos, tt) -// println(e.Description()) -// } -// } - -// type A struct { -// A string -// } - -// type B struct { -// A int `json:"a,string"` -// } - -// func TestErrors_MismatchType(t *testing.T) { -// testCases := []errTest { -// { -// in: `{"a": 123}`, -// ptr: &A{}, -// pos: 6, -// }, -// { -// in: ` {"a": true}`, -// ptr: &A{}, -// pos: 7, -// }, -// { -// in: ` {"a": true}`, -// ptr: &B{}, -// pos: 7, -// }, -// // { -// // in: ` {"a": "true"}`, -// // ptr: &B{}, -// // pos: 7, -// // }, -// { -// in: ` [1, 2, "3", 4]`, -// ptr: &[4]int{}, -// pos: 9, -// }, -// { -// in: ` [1, 2, "3", 4]`, -// ptr: &[]int{}, -// pos: 9, -// }, -// { -// in: ` [1, 256, "3", 4]`, -// ptr: &[]int8{}, -// pos: 5, -// }, -// { -// in: ` [1, 256, "3", 4]`, -// ptr: &[]byte{}, // []byte is special -// pos: 1, -// }, -// { -// in: ` {"key": 123}`, -// ptr: &map[string]string{}, -// pos: 9, -// }, -// { -// in: ` {"key": 123}`, -// ptr: &map[int64]interface{}{}, -// pos: 3, -// }, -// { -// in: ` "key"`, -// ptr: new(json.Number), -// pos: 2, -// }, -// } - -// for _, tt := range testCases { -// spew.Dump(tt) -// got := NewDecoder(tt.in).Decode(tt.ptr) -// e := got.(*MismatchTypeError); -// assert.Equal(t, tt.pos, e.Pos) -// println(e.Description()) - -// exp := json.Unmarshal([]byte(tt.in), tt.ptr) -// assert.Error(t, exp) -// } -// } - -// func TestErrors_ParseMultiJsonError(t *testing.T) { -// testCases := []errTest { -// { -// in: ` {"a":"b"} {"1":"2"} true false null 1.23 0 -1 1e123 456 "hello" "" "\\" "\"" fx`, -// pos: 84, -// }, -// } - -// for _, tt := range testCases { -// dec := NewDecoder(tt.in) -// var val interface{} -// var err error -// for err == nil { -// err = dec.Decode(&val) -// spew.Dump(val) -// } - -// e := err.(SyntaxError); -// assert.Equal(t, tt.pos, e.Pos) -// println(e.Description()) - -// jdec := json.NewDecoder(strings.NewReader(tt.in)) -// var jval interface{} -// var jerr error -// for jerr == nil { -// jerr = jdec.Decode(&jval) -// } -// println(jerr.Error()) -// } -// } diff --git a/internal/decoder/api/stream.go b/internal/decoder/api/stream.go index 2bc522c7a..8a8102dd5 100644 --- a/internal/decoder/api/stream.go +++ b/internal/decoder/api/stream.go @@ -67,25 +67,16 @@ func NewStreamDecoder(r io.Reader) *StreamDecoder { func (self *StreamDecoder) Decode(val interface{}) (err error) { // read more data into buf if self.More() { - // println(string(self.buf)) var s = self.scanp try_skip: var e = len(self.buf) - // println("s:", s, "e:", e, "scanned:",self.scanned, "scanp:",self.scanp, self.buf) var src = rt.Mem2Str(self.buf[s:e]) - // if len(src) > 5 { - // println(src[:5], src[len(src)-5:]) - // } else { - // println(src) - // } // try skip var x = 0; if y := native.SkipOneFast(&src, &x); y < 0 { if self.readMore() { - // println("more") goto try_skip } else { - // println("no more") err = SyntaxError{e, self.s, types.ParsingError(-s), ""} self.setErr(err) return @@ -95,7 +86,6 @@ func (self *StreamDecoder) Decode(val interface{}) (err error) { e = x + s } - // println("decode: ", s, e) // must copy string here for safety self.Decoder.Reset(string(self.buf[s:e])) err = self.Decoder.Decode(val) @@ -107,13 +97,11 @@ func (self *StreamDecoder) Decode(val interface{}) (err error) { self.scanp = e _, empty := self.scan() if empty { - // println("recycle") // no remain valid bytes, thus we just recycle buffer mem := self.buf self.buf = nil freeBytes(mem) } else { - // println("keep") // remain undecoded bytes, move them onto head n := copy(self.buf, self.buf[self.scanp:]) self.buf = self.buf[:n] @@ -129,7 +117,6 @@ func (self *StreamDecoder) Decode(val interface{}) (err error) { // InputOffset returns the input stream byte offset of the current decoder position. // The offset gives the location of the end of the most recently returned token and the beginning of the next token. func (self *StreamDecoder) InputOffset() int64 { - // println("input offset",self.scanned, self.scanp) return self.scanned + int64(self.scanp) } @@ -243,12 +230,10 @@ func realloc(buf *[]byte) bool { l := uint(len(*buf)) c := uint(cap(*buf)) if c == 0 { - // println("use pool!") *buf = bufPool.Get().([]byte) return true } if c - l <= c >> minLeftBufferShift { - // println("realloc!") e := l+(l>>minLeftBufferShift) if e <= c { e = c*2 diff --git a/internal/decoder/api/stream_test.go b/internal/decoder/api/stream_test.go index 0e83d54ea..222d4cf3f 100644 --- a/internal/decoder/api/stream_test.go +++ b/internal/decoder/api/stream_test.go @@ -308,7 +308,6 @@ func BenchmarkDecodeStream_Sonic(b *testing.B) { var str = _Double_JSON + strings.Repeat(" ", int(DefaultBufferSize-10)) + _Double_JSON b.ResetTimer() for i:=0; i= len(s.stack) { - // panic("slice len") - // } s.stack[s.index].con = p s.stack[s.index].remain = uint64(remain) if isObj { @@ -1034,7 +1029,6 @@ _object_key: val = newSp isObj = false size = newSize - ////println("new array size is ", newSize) goto _arr_val; case KStringCommon: ctx.efacePool.ConvTstring(node.StringRef(ctx), val) @@ -1084,7 +1078,6 @@ _object_key: goto _object_key; } else { val = rt.PtrAdd(parent, rt.AnyType.Size) - //println("parent1 is ", parent, "val is ", val) goto _arr_val; } @@ -1158,7 +1151,6 @@ _arr_val: // check size size -= 1 - ////println("remain arr size is ", size) if size != 0 { val = rt.PtrAdd(val, rt.AnyType.Size) goto _arr_val; @@ -1167,9 +1159,6 @@ _arr_val: parent, size, isObj = ctx.Stack.Pop() - - ////println("parent is ", parent, "remain is ", size, " is obj ", isObj) - // parent is empty if parent == nil { if isObj { @@ -1189,7 +1178,6 @@ _arr_val: goto _object_key; } else { val = rt.PtrAdd(parent, rt.AnyType.Size) - //println("parent2 is ", parent, "val is ", val) goto _arr_val; } } diff --git a/internal/encoder/vm/vm.go b/internal/encoder/vm/vm.go index b56145903..b75ba807a 100644 --- a/internal/encoder/vm/vm.go +++ b/internal/encoder/vm/vm.go @@ -65,8 +65,6 @@ func Execute(b *[]byte, p unsafe.Pointer, s *vars.Stack, flags uint64, prog *ir. pc++ op := ins.Op() - // print_instr(buf, pc, op, ins, p) - switch op { case ir.OP_goto: pc = ins.Vi() diff --git a/internal/optcaching/fcache.go b/internal/optcaching/fcache.go index 7a4883b29..afa7e7105 100644 --- a/internal/optcaching/fcache.go +++ b/internal/optcaching/fcache.go @@ -236,9 +236,7 @@ func (self *NormalFieldMap) getCaseInsensitive(name string) int { offset := int(*(*int32)(unsafe.Pointer(uintptr(p) + uintptr(5 * len(name) + 1)))) + self.lowOffset for i := 0; i < cnt; i++ { key := rt.Mem2Str(self.keys[offset: offset + len(name)]) - println("compare with loer is ---> ket is ", key, lower) if key == lower { - println("compare with loer is ---> ket is inde is ", key, lower, int(self.keys[offset + len(name)])) return int(self.keys[offset + len(name)]) } offset += len(name) + 1