chore: reduce a little memory

This commit is contained in:
gVisor bot 2022-04-09 22:13:45 +08:00
parent 0042b5de3b
commit 2b5e14533b

View file

@ -7,6 +7,10 @@ type Node struct {
} }
func (n *Node) getChild(s string) *Node { func (n *Node) getChild(s string) *Node {
if n.children == nil {
return nil
}
return n.children[s] return n.children[s]
} }
@ -15,12 +19,16 @@ func (n *Node) hasChild(s string) bool {
} }
func (n *Node) addChild(s string, child *Node) { func (n *Node) addChild(s string, child *Node) {
if n.children == nil {
n.children = map[string]*Node{}
}
n.children[s] = child n.children[s] = child
} }
func newNode(data any) *Node { func newNode(data any) *Node {
return &Node{ return &Node{
Data: data, Data: data,
children: map[string]*Node{}, children: nil,
} }
} }