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
Closed

encoding/json: simplify dominantField #18037

jba opened this issue Nov 23, 2016 · 2 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@jba
Copy link
Contributor

jba 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
Copy link
Member

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 added NeedsFix The path to resolution is known, but the work has not been done. help wanted labels Apr 17, 2018
@ALTree ALTree modified the milestones: Go1.11, Unplanned Apr 17, 2018
@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Apr 17, 2019
@rsc rsc unassigned jba Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants