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

Ignore complexity of children in maps/slices/arrays #382

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions _generated/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,19 @@ type NumberJSONSample struct {
Map map[string]json.Number
OE json.Number `msg:",omitempty"`
}

type Flobbity struct {
A Flobs `msg:"a,omitempty"`
B Flobs `msg:"b,omitempty"`
}

type Flobs []Flob

type Flob struct {
X Numberwang `msg:"x"`
Y int8 `msg:"y"`
Z int8 `msg:"z"`
W int32 `msg:"w"`
}

type Numberwang int8
13 changes: 10 additions & 3 deletions gen/elem.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ func (a *Array) Copy() Elem {
return &b
}

func (a *Array) Complexity() int { return 1 + a.Els.Complexity() }
func (a *Array) Complexity() int {
// We consider the complexity constant and leave the children to decide on their own.
return 2
}

// ZeroExpr returns the zero/empty expression or empty string if not supported. Unsupported for this case.
func (a *Array) ZeroExpr() string { return "" }
Expand Down Expand Up @@ -313,7 +316,10 @@ func (m *Map) Copy() Elem {
return &g
}

func (m *Map) Complexity() int { return 2 + m.Value.Complexity() }
func (m *Map) Complexity() int {
// Complexity of maps are considered constant. Children should decide on their own.
return 3
}

// ZeroExpr returns the zero/empty expression or empty string if not supported. Always "nil" for this case.
func (m *Map) ZeroExpr() string { return "nil" }
Expand Down Expand Up @@ -360,7 +366,8 @@ func (s *Slice) Copy() Elem {
}

func (s *Slice) Complexity() int {
return 1 + s.Els.Complexity()
// We leave the inlining decision to the slice children.
return 2
}

// ZeroExpr returns the zero/empty expression or empty string if not supported. Always "nil" for this case.
Expand Down
Loading