Skip to content

Commit

Permalink
cue: remove unneeded fields from goField
Browse files Browse the repository at this point in the history
These were carried over from JSON, where they are used
to efficiently encode the fields as JSON keys repeatedly.
Here we don't deal with JSON encoding or decoding at all.

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: Ifa86da924cf261a86ba58f3e888c294f450e49f7
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201761
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Roger Peppe <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mvdan committed Sep 25, 2024
1 parent 774e40e commit 1b45c99
Showing 1 changed file with 0 additions and 14 deletions.
14 changes: 0 additions & 14 deletions cue/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,6 @@ type goField struct {
nameBytes []byte // []byte(name)
equalFold func(s, t []byte) bool // bytes.EqualFold or equivalent

nameNonEsc string // `"` + name + `":`
nameEscHTML string // `"` + HTMLEscape(name) + `":`

tag bool
index []int
typ reflect.Type
Expand Down Expand Up @@ -518,9 +515,6 @@ func typeFields(t reflect.Type) structFields {
// Fields found.
var fields []goField

// Buffer to run HTMLEscape on field names.
var nameEscBuf bytes.Buffer

for len(next) > 0 {
current, next = next, current[:0]
count, nextCount = nextCount, map[reflect.Type]int{}
Expand Down Expand Up @@ -584,14 +578,6 @@ func typeFields(t reflect.Type) structFields {
field.nameBytes = []byte(field.name)
field.equalFold = foldFunc(field.nameBytes)

// Build nameEscHTML and nameNonEsc ahead of time.
nameEscBuf.Reset()
nameEscBuf.WriteString(`"`)
json.HTMLEscape(&nameEscBuf, field.nameBytes)
nameEscBuf.WriteString(`":`)
field.nameEscHTML = nameEscBuf.String()
field.nameNonEsc = `"` + field.name + `":`

fields = append(fields, field)
if count[f.typ] > 1 {
// If there were multiple instances, add a second,
Expand Down

0 comments on commit 1b45c99

Please sign in to comment.