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

Remove isChild from fastJsonNode #5184

Merged
merged 1 commit into from
Apr 14, 2020
Merged
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
25 changes: 10 additions & 15 deletions query/outputnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ func ToJson(l *Latency, sgl []*SubGraph) ([]byte, error) {
return sgr.toFastJSON(l)
}

func makeScalarNode(attr string, isChild bool, val []byte, list bool) *fastJsonNode {
func makeScalarNode(attr string, val []byte, list bool) *fastJsonNode {
return &fastJsonNode{
attr: attr,
isChild: isChild,
scalarVal: val,
list: list,
}
Expand All @@ -68,7 +67,6 @@ func makeScalarNode(attr string, isChild bool, val []byte, list bool) *fastJsonN
type fastJsonNode struct {
attr string
order int // relative ordering (for sorted results)
isChild bool
scalarVal []byte
attrs []*fastJsonNode
list bool
Expand All @@ -80,7 +78,7 @@ func (fj *fastJsonNode) AddValue(attr string, v types.Val) {

func (fj *fastJsonNode) AddListValue(attr string, v types.Val, list bool) {
if bs, err := valToBytes(v); err == nil {
fj.attrs = append(fj.attrs, makeScalarNode(attr, false, bs, list))
fj.attrs = append(fj.attrs, makeScalarNode(attr, bs, list))
}
}

Expand All @@ -94,24 +92,21 @@ func (fj *fastJsonNode) AddMapChild(attr string, val *fastJsonNode, isRoot bool)
}

if childNode != nil {
val.isChild = true
val.attr = attr
childNode.attrs = append(childNode.attrs, val.attrs...)
} else {
val.isChild = false
val.attr = attr
fj.attrs = append(fj.attrs, val)
}
}

func (fj *fastJsonNode) AddListChild(attr string, child *fastJsonNode) {
child.attr = attr
child.isChild = true
child.list = true
fj.attrs = append(fj.attrs, child)
}

func (fj *fastJsonNode) New(attr string) *fastJsonNode {
return &fastJsonNode{attr: attr, isChild: false}
return &fastJsonNode{attr: attr}
}

func (fj *fastJsonNode) SetUID(uid uint64, attr string) {
Expand All @@ -123,8 +118,7 @@ func (fj *fastJsonNode) SetUID(uid uint64, attr string) {
}
}
}
fj.attrs = append(fj.attrs, makeScalarNode(attr, false, []byte(fmt.Sprintf("\"%#x\"", uid)),
false))
fj.attrs = append(fj.attrs, makeScalarNode(attr, []byte(fmt.Sprintf("\"%#x\"", uid)), false))
}

func (fj *fastJsonNode) IsEmpty() bool {
Expand Down Expand Up @@ -376,7 +370,7 @@ func (fj *fastJsonNode) encode(out *bytes.Buffer) error {
if err := cur.writeKey(out); err != nil {
return err
}
if cur.isChild || cur.list {
if cur.list {
if _, err := out.WriteRune('['); err != nil {
return err
}
Expand All @@ -386,7 +380,7 @@ func (fj *fastJsonNode) encode(out *bytes.Buffer) error {
if err := cur.encode(out); err != nil {
return err
}
if cnt != 1 || (cur.isChild || cur.list) {
if cnt != 1 || cur.list {
if _, err := out.WriteRune(']'); err != nil {
return err
}
Expand All @@ -405,15 +399,15 @@ func (fj *fastJsonNode) encode(out *bytes.Buffer) error {
return err
}
}
if (cur.isChild || cur.list) && !inArray {
if cur.list && !inArray {
if _, err := out.WriteRune('['); err != nil {
return err
}
}
if err := cur.encode(out); err != nil {
return err
}
if cnt != 1 || (cur.isChild || cur.list) {
if cnt != 1 || cur.list {
if _, err := out.WriteRune(']'); err != nil {
return err
}
Expand Down Expand Up @@ -706,6 +700,7 @@ func (sg *SubGraph) toFastJSON(l *Latency) ([]byte, error) {
return nil, err
}
}

return bufw.Bytes(), nil
}

Expand Down