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

jba opened this issue Nov 23, 2016 · 2 comments

encoding/json: simplify dominantField #18037

jba opened this issue Nov 23, 2016 · 2 comments


Copy link

@jba jba commented Nov 23, 2016

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


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



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


@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
Copy link

@mvdan mvdan 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
Copy link

@gopherbot gopherbot commented Apr 17, 2018

Change 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.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.