forked from mirror/go-json
Add optimized StructEnd operation
This commit is contained in:
parent
feeb05ad10
commit
1f5e0cb5fd
|
@ -238,7 +238,6 @@ func (t opType) fieldToStringTagField() opType {
|
|||
createOpType("MapValue", "MapValue"),
|
||||
createOpType("MapEnd", "Op"),
|
||||
createOpType("StructFieldRecursiveEnd", "Op"),
|
||||
createOpType("StructEnd", "StructField"),
|
||||
createOpType("StructAnonymousEnd", "StructField"),
|
||||
}
|
||||
for _, typ := range primitiveTypesUpper {
|
||||
|
@ -412,6 +411,62 @@ func (t opType) fieldToStringTagField() opType {
|
|||
}
|
||||
}
|
||||
}
|
||||
for _, escapedOrNot := range []string{"", "Escaped"} {
|
||||
for _, opt := range []string{"", "OmitEmpty", "StringTag"} {
|
||||
for _, typ := range append(primitiveTypesUpper, "") {
|
||||
escapedOrNot := escapedOrNot
|
||||
opt := opt
|
||||
typ := typ
|
||||
|
||||
op := fmt.Sprintf(
|
||||
"Struct%sEnd%s%s",
|
||||
escapedOrNot,
|
||||
opt,
|
||||
typ,
|
||||
)
|
||||
opTypes = append(opTypes, opType{
|
||||
Op: op,
|
||||
Code: "StructField",
|
||||
Indent: func() string { return fmt.Sprintf("%sIndent", op) },
|
||||
Escaped: func() string {
|
||||
switch typ {
|
||||
case "String", "StringPtr", "StringNPtr":
|
||||
return fmt.Sprintf(
|
||||
"StructEscapedEnd%sEscaped%s",
|
||||
opt,
|
||||
typ,
|
||||
)
|
||||
}
|
||||
return fmt.Sprintf(
|
||||
"StructEscapedEnd%s%s",
|
||||
opt,
|
||||
typ,
|
||||
)
|
||||
},
|
||||
HeadToPtrHead: func() string { return op },
|
||||
HeadToNPtrHead: func() string { return op },
|
||||
HeadToAnonymousHead: func() string { return op },
|
||||
HeadToOmitEmptyHead: func() string { return op },
|
||||
HeadToStringTagHead: func() string { return op },
|
||||
PtrHeadToHead: func() string { return op },
|
||||
FieldToOmitEmptyField: func() string {
|
||||
return fmt.Sprintf(
|
||||
"Struct%sEndOmitEmpty%s",
|
||||
escapedOrNot,
|
||||
typ,
|
||||
)
|
||||
},
|
||||
FieldToStringTagField: func() string {
|
||||
return fmt.Sprintf(
|
||||
"Struct%sEndStringTag%s",
|
||||
escapedOrNot,
|
||||
typ,
|
||||
)
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
indentOpTypes := []opType{}
|
||||
for _, typ := range opTypes {
|
||||
typ := typ
|
||||
|
|
31712
encode_optype.go
31712
encode_optype.go
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue