aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/encoding/json/encode.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go
index 5e47413f23..0cca15b6e0 100644
--- a/src/encoding/json/encode.go
+++ b/src/encoding/json/encode.go
@@ -296,6 +296,8 @@ const hex = "0123456789abcdef"
// An encodeState encodes JSON into a bytes.Buffer.
type encodeState struct {
+ ptrSeen map[any]struct{}
+
bytes.Buffer // accumulated output
// Keep track of what pointers we've seen in the current recursive call
@@ -304,7 +306,6 @@ type encodeState struct {
// startDetectingCyclesAfter, so that we skip the work if we're within a
// reasonable amount of nested pointers deep.
ptrLevel uint
- ptrSeen map[any]struct{}
}
const startDetectingCyclesAfter = 1000
@@ -710,9 +711,9 @@ type structEncoder struct {
}
type structFields struct {
- list []field
byExactName map[string]*field
byFoldedName map[string]*field
+ list []field
}
func (se structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
@@ -1068,21 +1069,22 @@ func appendString[Bytes []byte | string](dst []byte, src Bytes, escapeHTML bool)
// A field represents a single field found in a struct.
type field struct {
- name string
- nameBytes []byte // []byte(name)
+ encoder encoderFunc
+
+ typ reflect.Type
+ name string
nameNonEsc string // `"` + name + `":`
nameEscHTML string // `"` + HTMLEscape(name) + `":`
- tag bool
index []int
- typ reflect.Type
+ nameBytes []byte // []byte(name)
+
+ tag bool
omitEmpty bool
omitZero bool
isZero func(reflect.Value) bool
quoted bool
-
- encoder encoderFunc
}
type isZeroer interface {
@@ -1308,7 +1310,7 @@ func typeFields(t reflect.Type) structFields {
foldedNameIndex[string(foldName(field.nameBytes))] = &fields[i]
}
}
- return structFields{fields, exactNameIndex, foldedNameIndex}
+ return structFields{exactNameIndex, foldedNameIndex, fields}
}
// dominantField looks through the fields, all of which are known to