From 2b5e14533bb0c6ce764c92a31c24e4fea4dc468c Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sat, 9 Apr 2022 22:13:45 +0800 Subject: [PATCH] chore: reduce a little memory --- component/trie/node.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/component/trie/node.go b/component/trie/node.go index 67ef64a4..05f1d840 100644 --- a/component/trie/node.go +++ b/component/trie/node.go @@ -7,6 +7,10 @@ type Node struct { } func (n *Node) getChild(s string) *Node { + if n.children == nil { + return nil + } + return n.children[s] } @@ -15,12 +19,16 @@ func (n *Node) hasChild(s string) bool { } func (n *Node) addChild(s string, child *Node) { + if n.children == nil { + n.children = map[string]*Node{} + } + n.children[s] = child } func newNode(data any) *Node { return &Node{ Data: data, - children: map[string]*Node{}, + children: nil, } }