forked from mirror/go-json
remove unnecessary code
This commit is contained in:
parent
35fdca6927
commit
79dba78e41
|
@ -421,7 +421,6 @@ func (c *StructCode) ToOpcode(ctx *compileContext) Opcodes {
|
||||||
head.NextField = end
|
head.NextField = end
|
||||||
head.Next = end
|
head.Next = end
|
||||||
head.End = end
|
head.End = end
|
||||||
end.PrevField = head
|
|
||||||
codes = append(codes, head, end)
|
codes = append(codes, head, end)
|
||||||
ctx.incIndex()
|
ctx.incIndex()
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ type Opcode struct {
|
||||||
Flags OpFlags
|
Flags OpFlags
|
||||||
|
|
||||||
Type *runtime.Type // go type
|
Type *runtime.Type // go type
|
||||||
PrevField *Opcode // prev struct field
|
|
||||||
Jmp *CompiledCode // for recursive call
|
Jmp *CompiledCode // for recursive call
|
||||||
ElemIdx uint32 // offset to access array/slice/map elem
|
ElemIdx uint32 // offset to access array/slice/map elem
|
||||||
Length uint32 // offset to access slice/map length or array length
|
Length uint32 // offset to access slice/map length or array length
|
||||||
|
@ -86,20 +85,6 @@ func (c *Opcode) IsEnd() bool {
|
||||||
return c.Op == OpEnd || c.Op == OpInterfaceEnd || c.Op == OpRecursiveEnd
|
return c.Op == OpEnd || c.Op == OpInterfaceEnd || c.Op == OpRecursiveEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Opcode) IsStructHeadOp() bool {
|
|
||||||
if c == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return strings.Contains(c.Op.String(), "Head")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Opcode) IsRecursiveOp() bool {
|
|
||||||
if c == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return strings.Contains(c.Op.String(), "Recursive")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Opcode) MaxIdx() uint32 {
|
func (c *Opcode) MaxIdx() uint32 {
|
||||||
max := uint32(0)
|
max := uint32(0)
|
||||||
for _, value := range []uint32{
|
for _, value := range []uint32{
|
||||||
|
@ -337,29 +322,18 @@ func copyOpcode(code *Opcode) *Opcode {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setTotalLengthToInterfaceOp(code *Opcode) {
|
func setTotalLengthToInterfaceOp(code *Opcode) {
|
||||||
c := code
|
for c := code; !c.IsEnd(); {
|
||||||
for c.Op != OpEnd && c.Op != OpInterfaceEnd {
|
|
||||||
if c.Op == OpInterface {
|
if c.Op == OpInterface {
|
||||||
c.Length = uint32(code.TotalLength())
|
c.Length = uint32(code.TotalLength())
|
||||||
}
|
}
|
||||||
switch c.Op.CodeType() {
|
c = c.IterNext()
|
||||||
case CodeArrayElem, CodeSliceElem, CodeMapKey:
|
|
||||||
c = c.End
|
|
||||||
default:
|
|
||||||
c = c.Next
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToEndCode(code *Opcode) *Opcode {
|
func ToEndCode(code *Opcode) *Opcode {
|
||||||
c := code
|
c := code
|
||||||
for c.Op != OpEnd && c.Op != OpInterfaceEnd {
|
for !c.IsEnd() {
|
||||||
switch c.Op.CodeType() {
|
c = c.IterNext()
|
||||||
case CodeArrayElem, CodeSliceElem, CodeMapKey:
|
|
||||||
c = c.End
|
|
||||||
default:
|
|
||||||
c = c.Next
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
@ -418,24 +392,12 @@ func (c *Opcode) copy(codeMap map[uintptr]*Opcode) *Opcode {
|
||||||
}
|
}
|
||||||
codeMap[addr] = copied
|
codeMap[addr] = copied
|
||||||
copied.End = c.End.copy(codeMap)
|
copied.End = c.End.copy(codeMap)
|
||||||
copied.PrevField = c.PrevField.copy(codeMap)
|
|
||||||
copied.NextField = c.NextField.copy(codeMap)
|
copied.NextField = c.NextField.copy(codeMap)
|
||||||
copied.Next = c.Next.copy(codeMap)
|
copied.Next = c.Next.copy(codeMap)
|
||||||
copied.Jmp = c.Jmp
|
copied.Jmp = c.Jmp
|
||||||
return copied
|
return copied
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Opcode) BeforeLastCode() *Opcode {
|
|
||||||
code := c
|
|
||||||
for {
|
|
||||||
nextCode := code.IterNext()
|
|
||||||
if nextCode.IsEnd() {
|
|
||||||
return code
|
|
||||||
}
|
|
||||||
code = nextCode
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Opcode) TotalLength() int {
|
func (c *Opcode) TotalLength() int {
|
||||||
var idx int
|
var idx int
|
||||||
code := c
|
code := c
|
||||||
|
@ -622,36 +584,6 @@ func (c *Opcode) Dump() string {
|
||||||
return strings.Join(codes, "\n")
|
return strings.Join(codes, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func prevField(code *Opcode, removedFields map[*Opcode]struct{}) *Opcode {
|
|
||||||
if _, exists := removedFields[code]; exists {
|
|
||||||
return prevField(code.PrevField, removedFields)
|
|
||||||
}
|
|
||||||
return code
|
|
||||||
}
|
|
||||||
|
|
||||||
func nextField(code *Opcode, removedFields map[*Opcode]struct{}) *Opcode {
|
|
||||||
if _, exists := removedFields[code]; exists {
|
|
||||||
return nextField(code.NextField, removedFields)
|
|
||||||
}
|
|
||||||
return code
|
|
||||||
}
|
|
||||||
|
|
||||||
func linkPrevToNextField(cur *Opcode, removedFields map[*Opcode]struct{}) {
|
|
||||||
prev := prevField(cur.PrevField, removedFields)
|
|
||||||
prev.NextField = nextField(cur.NextField, removedFields)
|
|
||||||
code := prev
|
|
||||||
for {
|
|
||||||
nextCode := code.IterNext()
|
|
||||||
if nextCode == cur {
|
|
||||||
code.Next = cur.NextField
|
|
||||||
break
|
|
||||||
} else if nextCode.Op == OpEnd {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
code = nextCode
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newSliceHeaderCode(ctx *compileContext) *Opcode {
|
func newSliceHeaderCode(ctx *compileContext) *Opcode {
|
||||||
idx := opcodeOffset(ctx.ptrIndex)
|
idx := opcodeOffset(ctx.ptrIndex)
|
||||||
ctx.incPtrIndex()
|
ctx.incPtrIndex()
|
||||||
|
|
|
@ -11,7 +11,7 @@ func TestOpcodeSize(t *testing.T) {
|
||||||
const uintptrSize = 4 << (^uintptr(0) >> 63)
|
const uintptrSize = 4 << (^uintptr(0) >> 63)
|
||||||
if uintptrSize == 8 {
|
if uintptrSize == 8 {
|
||||||
size := unsafe.Sizeof(encoder.Opcode{})
|
size := unsafe.Sizeof(encoder.Opcode{})
|
||||||
if size != 128 {
|
if size != 120 {
|
||||||
t.Fatalf("unexpected opcode size: expected 128bytes but got %dbytes", size)
|
t.Fatalf("unexpected opcode size: expected 128bytes but got %dbytes", size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue