Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: simplify dominantField #18037

Closed
jba opened this issue Nov 23, 2016 · 2 comments

Comments

Projects
None yet
6 participants
@jba
Copy link
Contributor

commented Nov 23, 2016

What version of Go are you using (go version)?

1.7.3

What operating system and processor architecture are you using (go env)?

any

Enhancement

Since byName sorts by index depth and tag presence, the dominant field is always the first. So the dominantField function can be simplified to checking for the error case: more than one field at top level, both tagged or both untagged.

func dominantField(fs []field) (field, bool) {
    if len(fs) > 1 && len(fs[0].index) == len(fs[1].index) && fs[0].tag == fs[1].tag {
        return field{}, false
    }
    return fs[0], true
}

See https://code-review.googlesource.com/9552.

@bradfitz bradfitz changed the title encoding/json encoding/json: simplify dominantField Nov 24, 2016

@bradfitz bradfitz added this to the Go1.9 milestone Nov 24, 2016

@mvdan

This comment has been minimized.

Copy link
Member

commented May 11, 2017

@jba I'm not sure I understand the point of this issue - are you going to send a CL with the simplification?

@ALTree ALTree modified the milestones: Go1.10, Go1.9 Jun 2, 2017

@rsc rsc modified the milestones: Go1.10, Go1.11 Nov 22, 2017

@ALTree ALTree modified the milestones: Go1.11, Unplanned Apr 17, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Apr 17, 2018

Change https://golang.org/cl/107598 mentions this issue: encoding/json: simplify dominantField

@gopherbot gopherbot closed this in fc21598 Apr 17, 2018

@golang golang locked and limited conversation to collaborators Apr 17, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.